If you find any post useful then, please do share with others. Thanks!

Popular Posts

Contact

Email me

Need help and that also free? I like to learn this way, in case of any question or for a small task, please feel free to email me with details and example data, if required.

Friday, February 3, 2023

SQL Query in Excel using Power Query

 --For running SQL Query using Power Query, Go to Data Tab, Get Data, From Other Sources, Blank Query, then in query window click on Advanced Editor and use below syntax as per need.


let

    Source = Sql.Database("ServerName",  "DatabaseName", [Query=" Select ID, personname from abc..person where ID= 306258"])

in

    Source

And if we want to use Query syntax from Excel file where it is available as  a named range then use below syntax. Please note the QueryValue in below syntax is a named range cell where query is available

let

    Source = Sql.Database("ServerName",  "DatabaseName", [Query= Excel.CurrentWorkbook(){[Name="QueryValue"]}[Content]{0}[Column1]])

in

    Source