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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
borlip
Advocate I
Advocate I

Executing Table.Group on SQL Server

We are using SQL Server as a source of Power BI.

 

My Query has Table.Group() function. Seems like power bi doesn’t know how to translate Table.Group() into tsql GROUP BY. As a result, it downloads enormous amount of records from the sql server into the memory and then executes grouping in the memory of Power BI Designer!!!

As a result, it takes forever and there is a huge traffic impact on our network.

1 ACCEPTED SOLUTION

Yeah :(.

 

There's an outstanding medium-term work item to give better visibility in PBI Desktop for what runs on the server vs locally, so you don't have to discover the hard way. In principle, there's no reason we couldn't calculate the start of the week on the server, but there's a really long tail of functions we don't currently fold and no obvious way to prioritize between them. If there are specific functions like Date.StartOfWeek that you think are critical to support, consider filing a request at UserVoice for those particular functions.

View solution in original post

6 REPLIES 6
curth
Power BI Team
Power BI Team

Whether or not a given invocation of Table.Group can be pushed to run on the back end depends on the kind of aggregate operations you're performing inside the grouping. For instance,

 

= Table.Group(Source, {"GroupId"}, {{"Count", each Table.RowCount(_), type number}})

 

might fold because Table.RowCount is supported on the back-end, but

 

= Table.Group(Source, {"GroupId"}, {{"Median", each List.Median([Price]), type number}})

 

might not, because List.Median isn't supported in SQL.

 

(This assumes, of course, that there wasn't an earlier operation which blocked folding of subsequent operations.)

You were right, Group is converted to tsql. However, I my case one of the group keys has gone through Transformation (StartOfWeek). StartOfWeek can't be translated to tsql and it causes the entire table with millions of rows to get downloaded to the client.... 😞

 

 

let
Source = Sql.Database("AFS-SQL01", "AFSXchange"),
dbo_BuyConsignments = Source{[Schema="dbo",Item="BuyConsignments"]}[Data],
#"Calculated Start of Week" = Table.TransformColumns(dbo_BuyConsignments,{{"ConsignmentDate", Date.StartOfWeek, type datetime}}),
#"Grouped Rows" = Table.Group(#"Calculated Start of Week", {"Customer_Id", "Carrier", "ConsignmentDate"}, {{"Count", each List.Sum([FreightCharges]), type number}})
in
#"Grouped Rows"

Yeah :(.

 

There's an outstanding medium-term work item to give better visibility in PBI Desktop for what runs on the server vs locally, so you don't have to discover the hard way. In principle, there's no reason we couldn't calculate the start of the week on the server, but there's a really long tail of functions we don't currently fold and no obvious way to prioritize between them. If there are specific functions like Date.StartOfWeek that you think are critical to support, consider filing a request at UserVoice for those particular functions.

Visibility around what is done in memory and what is executed remotely, as well as the impact on the network is very important. The tool is meant to be used by not technical people, but the impact might be very bad.

I'll add to the user voice. I'm surprised that no one noticed it before....

I've been doing Sum, which should be supported by tsql.

#"Grouped Rows" = Table.Group(#"Filtered Rows", {"Customers.CustomerSubCode", "Carrier", "StartOfWeek"}, {{"FreightCharges", each List.Sum([FreightCharges]), type number}, {"TotalNett", each List.Sum([TotalNett]), type number}})

Greg_Deckler
Super User
Super User

This is correct, Power Query uses M code and is not translating this into native functions. In addition, the tabular data modeling of Excel and Power BI Desktop are in memory technologies. I would recommend that, as a source, you include the SQL Group By clause in your initial source query or create a stored procedure in SQL that includes the Group By clause and simply EXEC that stored procedure.

 

What does your SQL source select statement currently look like?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors