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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
srpeters
Helper II
Helper II

Sum of a row passing two conditions

Is there a way to create a measure that returns the sum of a column for each row grouped by two conditions without using the group by feature in Power Query? Here is some sample data to explain:

srpeters_1-1725455773561.png

 

 

The measure would have to return the total cost for each customer split up by each Product ID. For example, if I used this measure in a calculated column, the measure would return 6 not 3 for the second to last row. I can not group the columns in Power Query because I need the months. I tried to use calculate and filter by Customer ID >= Earlier(Customer ID) and Product ID >= Earlier (Product ID) after sorting both columns in the Power Query but this did not seem to work due to the size of the table I am working with. 

 

Thank you!

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@srpeters Try this (below) You can use the measure in a table visual with Customer ID and Product ID

Column = 
  VAR __Customer = [Customer ID]
  VAR __Product = [Product ID]
  VAR __Table = FILTER( 'Table', [Custmer ID] = __Customer && [Product ID] = __Product )
  VAR __Result = SUMX( __Table, [Cost] )
RETURN
  __Result


Measure = 
  VAR __Customer = MAX( [Customer ID] )
  VAR __Product = MAX( [Product ID] )
  VAR __Table = FILTER( 'Table', [Custmer ID] = __Customer && [Product ID] = __Product )
  VAR __Result = SUMX( __Table, [Cost] )
RETURN
  __Result

 



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...

View solution in original post

Rupak_bi
Post Prodigy
Post Prodigy

Hi @srpeters 

Here is the solution

Rupak_bi_0-1725458030251.png

Sum = calculate(sum('Table (6)'[Cost]),ALLEXCEPT('Table (6)','Table (6)'[Coustomer ID],'Table (6)'[Product ID]))
 
you can use the same DAX in Measure as well


Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

View solution in original post

3 REPLIES 3
Rupak_bi
Post Prodigy
Post Prodigy

Hi @srpeters 

Here is the solution

Rupak_bi_0-1725458030251.png

Sum = calculate(sum('Table (6)'[Cost]),ALLEXCEPT('Table (6)','Table (6)'[Coustomer ID],'Table (6)'[Product ID]))
 
you can use the same DAX in Measure as well


Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

This worked great, thank you!

Greg_Deckler
Super User
Super User

@srpeters Try this (below) You can use the measure in a table visual with Customer ID and Product ID

Column = 
  VAR __Customer = [Customer ID]
  VAR __Product = [Product ID]
  VAR __Table = FILTER( 'Table', [Custmer ID] = __Customer && [Product ID] = __Product )
  VAR __Result = SUMX( __Table, [Cost] )
RETURN
  __Result


Measure = 
  VAR __Customer = MAX( [Customer ID] )
  VAR __Product = MAX( [Product ID] )
  VAR __Table = FILTER( 'Table', [Custmer ID] = __Customer && [Product ID] = __Product )
  VAR __Result = SUMX( __Table, [Cost] )
RETURN
  __Result

 



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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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