Query Excel with cell criteria

Asked

Viewed 269 times

0

I have a spreadsheet based on an SQL code powered by our database. But every month I have to enter the code and change the dates to get this information right.

I want Power Query to use the values of a cell to perform the query, not a fixed date in the code.

SELECT  fat_ntfger.ntg_dtr AS "HORARIO",
    cor_pessoa.pes_nom AS "PESSOA",
    fat_ntfger.ntg_doc AS "NFs",
    fat_ntfger.ntg_vlr AS "VALOR",
    fat_ntfger.ntg_vst AS "VALOR ST",
    fat_ntfger.ntg_ven AS "VENDEDOR",
    ROUND(SUM(fat_nftitm.nti_qtd),2) AS "QUANTIDADE VENDIDA"
        FROM fat_ntfger
    INNER JOIN cor_pessoa ON fat_ntfger.ntg_pes = cor_pessoa.pes_cod AND fat_ntfger.ntg_emp = cor_pessoa.pes_emp
    INNER JOIN fat_nftitm ON fat_ntfger.ntg_idx = fat_nftitm.nti_ntg 
    WHERE   fat_ntfger.ntg_dem >= "2019/11/01 00:00:00" AND 
        fat_ntfger.ntg_dem <= "2019/11/31 23:59:59" AND fat_ntfger.ntg_emp = 1 AND
        fat_ntfger.ntg_tip = "v" AND
        (fat_ntfger.ntg_opf = 76 OR fat_ntfger.ntg_opf = 79) AND
        fat_ntfger.ntg_est = "n" AND
        fat_ntfger.ntg_est <> 7 AND
        fat_ntfger.ntg_pes <> 228 AND 
        fat_ntfger.ntg_ven <> 1
        GROUP BY
        fat_nftitm.nti_ntg  
        ORDER BY ROUND(SUM(fat_nftitm.nti_qtd
        ),2) DESC

1 answer

0

You can try to create two variables and use the variables instead of the date itself

See image below

inserir a descrição da imagem aqui

  • Welcome John, your answer may be useful, however for better viewing change the image by the code contained in it. Also, as you are new to the site I invite you to do the tour, read the guide to How to ask and access to help center.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.