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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

SUMX with FILTER calculation in the same table

I have a table as follows that I need to sum up all the quantities and apply the sum to the product:

Sales  
PNQtyTotal Qty
AB25
BA48
BA48
CA55
AB25
AC24
AC24
AB15

When I try to use the following formula: Total QTY = SUMX(FILTER(Sales, Sales(PN) = Sales(PN)),Sales(Qty)) 

This is what I get where it gives me the total sum of the Qty column:

 

Sales  
PNQtyTotal Qty
AB222
BA422
BA422
CA522
AB222
AC222
AC222
AB122

 

It looks like it is not recognizing the expression "Sales(PN) = Sales(PN)". Is there a way to make the formula work?

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Sales(PN) = Sales(PN) is always true, so all your rows are included in the total.  Please try this expression instead.

 

NewMeasure = CALCULATE(SUM(Sales[Qty]), ALLEXCEPT(Sales, Sales[PN]))

 

To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

Sales(PN) = Sales(PN) is always true, so all your rows are included in the total.  Please try this expression instead.

 

NewMeasure = CALCULATE(SUM(Sales[Qty]), ALLEXCEPT(Sales, Sales[PN]))

 

To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thank you Pat! This worked perfectly.

ryan_mayu
Super User
Super User

@Anonymous 

please try

Measure = CALCULATE(sum('Table'[Qty]),ALL('Table'))

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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