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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Frbelotto
Frequent Visitor

Power Bi vs Power Query group by

Help! I own a huge database containing millions of rows of transactions. It does contain many columns with diverse information :

 

iFn3E.png

 

I am working on a power bi dashboard resuming such information, so, to reduce my input base for, I was using the "group by" on the power query, so, I am grouping such table by (command created by point and click options of power query) :

 

{"STATUS", "PRODUTO", "PARCEIRO", "MARCA", "data_transação"}, {{"Agg_Valor_Transação", each List.Sum([Valor_Transação]), type nullable number}, {"Agg_Receita", each List.Sum([RECEITA]), type nullable number}, {"Agg_Cashback", each List.Sum([CASHBACK]), type nullable number}})

 

It does work in power query as you can see below

1Rnxh.png

 

But as long as a close power query, the same table in power by shows me this values!

DSYYq.png

 

And wors! Every time I edit the query and open it in power by the results are increased!

obs : Such table currently does not contain any relationship defined in the model

Capturar.JPG

1 ACCEPTED SOLUTION
RossEdwards
Solution Sage
Solution Sage

Two methods to achieve this.  In the Source row of your query, click the cog icon and paste your SQL code into the box under "Advanced".

 

I prefer to use a function called Value.NativeQuery().  Its used like this (advanced editor):

 

let
    Source = <Your current source row>,
    QueryResult = Value.NativeQuery(Source, "
<SQL GOES HERE>
    ")
in
    QueryResult

 

View solution in original post

5 REPLIES 5
RossEdwards
Solution Sage
Solution Sage

Two methods to achieve this.  In the Source row of your query, click the cog icon and paste your SQL code into the box under "Advanced".

 

I prefer to use a function called Value.NativeQuery().  Its used like this (advanced editor):

 

let
    Source = <Your current source row>,
    QueryResult = Value.NativeQuery(Source, "
<SQL GOES HERE>
    ")
in
    QueryResult

 

Thanks!
A quick question. My data source table name is a kind weird.
A must use the table name under "", and the inside "" is breaking the sql text code. On python I solve this by using ' instead of ", but I couldnt do this on the PWBI advanced editor.

Frbelotto_0-1709302201062.png

 

 

 

The " character will be considered a special character, all you need to do is use it twice.  Chanage your code to:

FROM DB2I023A. ""ShoppingBB"" t1
RossEdwards
Solution Sage
Solution Sage

The Power Query editor preview window only uses a portion of the source data in its display.  When doing a 'close and apply', the full database dataset will be configured.  This can create instances where you get different numbers.

 

There are also occasions where unordered data can be considered in chunks in Power Query which can cause odd behaviour.  My recommendation is to group your data using an SQL query (or similar if on a different database).  Get the database to do the 'Group By' for you as part of the query statement.  It will likely perform faster too.

Thanks for the information. I tried using a similar SQL query on the db and I got same results of the preview. 

 

Anyway, how could I set the SQL query instead of power query? I was trying to see the "created query" to try understand what was wrong but I couldn't find how. 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.