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
Stemar_Aubert
Resolver I
Resolver I

Total of positive values only

Hello,

 

Consider the following table:

 

PRODUCTCATEGORYSALEPRICE
AAA10100
BBB2010
CCC30100
DDD40100

 

I am looking for a DAX measure that would yield the following result:

 

ProfitRegular = SUMX('TABLE'[SALE]-[PRICE])

Profit = IF([ProfitRegular] < 0, 0, [ProfitRegular])

 

 

PRODUCTPROFIT
A90
B0
C70
D60
TOTAL220

 

The issue is, I can only get following results using an array of solutions:

 

PRODUCTPROFIT
A90
B0
C70
D60
TOTAL210

 

While I can get DAX to solve correctly within a table, the total being its own context, it yields an amount not matching what the user is seeing, Effectively, capping the negatives values at 0 isn't working for the total.

 

Now, I am aware of means such as HASONEFILTER or ISCROSSFILTERED in combination with IF/SWITCH(TRUE() statements, however I also need to be able to filter using CATEGORY, meaning once the user selects multiple categories, everything is crossfiltered and thus the total starts being wrong once more.

 

Any ideas for a measure that effectively calculate the visual total ?

 

Thanks!

1 ACCEPTED SOLUTION

Ok, I've tested this one and it looks like it works

Profit = SUMX('Table', IF('Table'[Price]-'Table'[Sale] < 0, 0, 'Table'[Price]-'Table'[Sale]))

AntonioM_0-1650632160414.png

 

 

View solution in original post

5 REPLIES 5
AntonioM
Solution Sage
Solution Sage

I think you need to include the IF within the SUMX. That way the total will not sum the negative values

 

SUMX ( IF ( 'TABLE'[SALE]-[PRICE] < 0, 0,  'TABLE'[SALE]-[PRICE] )

 

Unfortunately, it only works at the lowest level of granularity. Going up, results stop making sense.

 

Ok, I've tested this one and it looks like it works

Profit = SUMX('Table', IF('Table'[Price]-'Table'[Sale] < 0, 0, 'Table'[Price]-'Table'[Sale]))

AntonioM_0-1650632160414.png

 

 

I was having a similar challenge with a different dataset and simply could not find or work out a viable solution and this totally saved me - thank you so much!

My mistake, it works! Must have missed something when integrating the if within sumx.


Thanks!

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.