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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MandoMongo
Regular Visitor

Grouping Question

I'm trying to write a dax measure that will group Sales by Product. 

I can see via a table with Sales and Product columns what the result should be...

MandoMongo_0-1714728989585.png

Yet the following measure is off somehow...

Gross Sales by Product =
CALCULATE(
    SUM(financials[Gross Sales]),
    ALLEXCEPT(financials,financials[Product])
)
 
MandoMongo_2-1714729148117.png

What am I doing wrong?


EDIT: There was somehow a country filter applied to the first table, it's calculating the same as my dax measure now. So just to confirm that application of DAX code works to group by...?

1 ACCEPTED SOLUTION
v-kaiyue-msft
Community Support
Community Support

Hi @MandoMongo ,

 

I want to confirm the valuable input provided by @sjoerdvn . However, I noticed that more detail is needed to fully understand this.

 

As @sjoerdvn  said, you just need to put the fields product and gross sales into the table visual object and it shows the grouped results.

vkaiyuemsft_0-1714985986731.png

 


If you want to verify that the filtered calculations are correct, you can create measure to do so.

Measure =
CALCULATE(SUM(financials[Gross Sales])),FILTER(ALL(financials),'financials'[Product] = "VTT" && 'financials'[Country] = "France"))

vkaiyuemsft_1-1714986013819.png


MEASURE shows the same results as in the table, so it's grouping and summing correctly.

 

Also, a deeper understanding of the concept of context may help you in solving the problem. Context is one of the most important DAX concepts to understand.There are two types of context in DAX: row context and filter context. We will first look at row contexts. More details can be found in the documentation: Learn DAX basics in Power BI Desktop - Power BI | Microsoft Learn.

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-kaiyue-msft
Community Support
Community Support

Hi @MandoMongo ,

 

I want to confirm the valuable input provided by @sjoerdvn . However, I noticed that more detail is needed to fully understand this.

 

As @sjoerdvn  said, you just need to put the fields product and gross sales into the table visual object and it shows the grouped results.

vkaiyuemsft_0-1714985986731.png

 


If you want to verify that the filtered calculations are correct, you can create measure to do so.

Measure =
CALCULATE(SUM(financials[Gross Sales])),FILTER(ALL(financials),'financials'[Product] = "VTT" && 'financials'[Country] = "France"))

vkaiyuemsft_1-1714986013819.png


MEASURE shows the same results as in the table, so it's grouping and summing correctly.

 

Also, a deeper understanding of the concept of context may help you in solving the problem. Context is one of the most important DAX concepts to understand.There are two types of context in DAX: row context and filter context. We will first look at row contexts. More details can be found in the documentation: Learn DAX basics in Power BI Desktop - Power BI | Microsoft Learn.

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you Clara, 

 

This is correct, thank you for demonstrating the way to write this as DAX. It's very helpful.

 

sjoerdvn
Super User
Super User

I don't understand what you're trying to do. If you have a product column, or better yet a related product dimension, you do not need any specific measures to display the sum per product. 

Hi, 

 

I know the measure is technically unnecessary it's just that I'm trying to understand how to approach it in DAX . I'm still trying to really understand the DAX approach and I am probably still thinking in SQL methods - but trying to see how you would do the equivalent if I had to in DAX. Appreciate you getting back on this.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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