Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Hello,
Consider the following table:
PRODUCT | CATEGORY | SALE | PRICE |
A | AA | 10 | 100 |
B | BB | 20 | 10 |
C | CC | 30 | 100 |
D | DD | 40 | 100 |
I am looking for a DAX measure that would yield the following result:
ProfitRegular = SUMX('TABLE'[SALE]-[PRICE])
Profit = IF([ProfitRegular] < 0, 0, [ProfitRegular])
PRODUCT | PROFIT |
A | 90 |
B | 0 |
C | 70 |
D | 60 |
TOTAL | 220 |
The issue is, I can only get following results using an array of solutions:
PRODUCT | PROFIT |
A | 90 |
B | 0 |
C | 70 |
D | 60 |
TOTAL | 210 |
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!
Solved! Go to 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]))
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]))
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!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
88 | |
75 | |
57 | |
39 | |
39 |
User | Count |
---|---|
117 | |
83 | |
79 | |
48 | |
42 |