22
votes

When I import data from Sql Server in Power Query, I can paste a query to be executed against the database. But later when I want to edit this query in Workbook Queries > Edit > Advanced Editor, I get something like this:

let
    Source = Sql.Database("server", "database", [Query="select#(lf)#(tab)*#(lf)from dbo.SomeView va#(lf)join dbo.SomeTable rm#(lf)#(tab)on rm.CatId=va.CatId#(lf)where 1=1#(lf)#(tab)and Month between 1501 and 1510#(lf)#(tab)and rm.Id in (1,2,3)"])
in
    Source

Please note that I'm using *, but with explicit column names this would look even worse.

I'd like to be able to see the query in a readable form, then copy it, execute in Management Studio, change something and paste back to Power Query. I know I could be using views as a source, or not using newlines and indentation, but that's not my point.

Any ideas on how to edit SQL in "normal" form? Or maybe I'm missing some hidden option.

EDIT: In case I'm not the only person in the world having problems finding this option, it's in:

Power Query > Launch Editor > View > Query Settings > Applied Steps > Source > Gear icon

Thanks Alejandro!

2
Thanks for posting that path. However, what you get after clicking the gear icon hardly resembles SQL style.Przemyslaw Remin

2 Answers

29
votes

If you click on the gear icon next to Source in the Query Settings pane you'll get a dialog with the SQL query in a readable form.

5
votes

Here's an illustration that complements the accepted answer.

enter image description here