Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

SQL Statement to query a Power BI Dataflow

Hello everyone

 

I've looked everywhere for an answer to this, I couldn't find a working example.

I have a very large Power BI Dataflow set up, will all Sales history over 10 years. My report, that I build on PBI desktop, only looks for the Sales of the current year.

 

Right now, using the Power Bi Dataflow connector, I can't find the place to write my SQL statement like "SELECT order_id FROM Sales WHERE Sales_date = 2021"

 

The M Code in Advanced Editor is this :

let
Source = PowerBI.Dataflows([]),
#"xxxxxxxxxxxxxxxx" = Source{[workspaceId="xxxxxxxxxxxxxxxx"]}[Data],
#"yyyyyyyyyyyyyyyy" = #"xxxxxxxxxxxxxxxx"{[dataflowId="yyyyyyyyyyyyyyyy"]}[Data],
#"Sales" = #"yyyyyyyyyyyyyyyy"{[entity="Sales"]}[Data]

 

 

Right now, PBI is pulling the whole history and all the columns of the table Sales Orders, and that takes almost 1 hour to perform Join in the subsequent steps.

 

Isn't there a way to amend the M code in order to pass a SQL statement to limit the amount of data transfered ?

 

Thanks a lot,

A

 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You should be able to add a filter step in your query editor to select just 2021 data. I don't think the dataflow necessarily uses SQL but that shouldn't matter.

 

Your query will look something like this with the new step.

let
    Source = PowerBI.Dataflows([]),
    #"xxxxxxxxxxxxxxxx" = Source{[workspaceId="xxxxxxxxxxxxxxxx"]}[Data],
    #"yyyyyyyyyyyyyyyy" = #"xxxxxxxxxxxxxxxx"{[dataflowId="yyyyyyyyyyyyyyyy"]}[Data],
    #"Sales" = #"yyyyyyyyyyyyyyyy"{[entity="Sales"]}[Data],
    #"Filtered Rows" = Table.SelectRows(#"Sales", each [sales_date] >= #date(2021, 1, 1))
in
    #"Filtered Rows"

View solution in original post

4 REPLIES 4
FireFighter1017
Advocate III
Advocate III

In order to run SQL statements, you need a database engine to run those statements.

A Dataflow is not storing data in a SQL database.  You can see that when you eexport your Dataflow in a JSON file on tag "ppdf:outputFileFormat".

Dataflow Gen1 is using csv files.

Dataglow Gen2 is using Apache Parquet files. 

If you can figure out a way to connect to the files generated by Gen2 Dataflows, You can run SQL statement on Parquet files by using Apache Spark SQL.

 

AlexisOlson
Super User
Super User

You should be able to add a filter step in your query editor to select just 2021 data. I don't think the dataflow necessarily uses SQL but that shouldn't matter.

 

Your query will look something like this with the new step.

let
    Source = PowerBI.Dataflows([]),
    #"xxxxxxxxxxxxxxxx" = Source{[workspaceId="xxxxxxxxxxxxxxxx"]}[Data],
    #"yyyyyyyyyyyyyyyy" = #"xxxxxxxxxxxxxxxx"{[dataflowId="yyyyyyyyyyyyyyyy"]}[Data],
    #"Sales" = #"yyyyyyyyyyyyyyyy"{[entity="Sales"]}[Data],
    #"Filtered Rows" = Table.SelectRows(#"Sales", each [sales_date] >= #date(2021, 1, 1))
in
    #"Filtered Rows"
Anonymous
Not applicable

Thanks @amitchandak 

Does that mean it's impossible to send a complex query with JOIN etc, to be executed on the Dataflows side before the data is sent back to Power BI ?

amitchandak
Super User
Super User

@Anonymous , You can use M parameter but that will limit data, can only be changed in the deployment pipeline

 

refer

https://www.fourmoo.com/2020/10/08/power-query-m-passing-parameters-dynamically-to-a-sql-server-quer...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors