Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi All - hope everyone is safe and doing ok out there!!!
I'm trying to sum up all the revenue for a state that is negative. If the value ends up being positive then I want it set to 0 - the point here to add up just the money we are losing. To add a level of complexity to it, for a given month there are various values that go into the overall value. So for example - a revenue value for March for Washington in my example may be -2500. In order to get that it had to add up the values for that state for that month so there were some positives and negative numbers in the calc to finally arrive at -2500. Lets say there was -5000 negative revenue and positive 2500 so the end value when put in a pbi table is -2500. My current calc is ignoring the positives and just adding up the negatives which is not what I want. So in that past example my dax is returning -5000 and not -2500. Here is an example of what I want:
I put my desired result from the dax i'm asking for help on - it would return that value. To give an example of the outputs that go into that value - it would look like this:
These are all the values that go on in the backend to come up with the -2500 value for WA. I tried a query and it ignored the positives and just returns a value of -5000. I think I need to sum up the group first. Here is the dax I tried:
SUMX('Table_Revenue',IF('Table_Revenue'[Revenue]<0,'Table_Revenue'[Revenue],0))
Would it be a sum inside of a sum?
Any suggestions are greatly appreciated!!
YB
@Anonymous ,
Try this and see if it works for you:
Proud to be a Datanaut!
Hi there - thanks for the reply - it works but needs a little tweaking. It does set the value to 0 but as you see - its still summing up the overall value with the positive. In your visual below - the desired revenue should be -3500, not -3000. In the last sum - its still counting the positive 500.
bump....
LOL, sorry @Anonymous ,
Please try the following measure:
desiredRevenue =
IF(
HASONEVALUE(revenue[state]),
IF(
SUM(revenue[revenue]) > 0,
0,
SUM(revenue[revenue])
),
SUMX(
FILTER(
SUMMARIZE(
revenue,
revenue[state],
"sumRev", SUM(revenue[revenue])
),
[sumRev] < 0
),
[sumRev]
)
)
I get the following result:
Proud to be a Datanaut!
The measure given by @BA_Pete can be written much simpler:
your revenue =
SUMX(
values( revenue[state] ),
var __rev = CALCULATE( SUM( revenue[revenue] ) )
return
( __rev < 0 ) * __rev
)
Best
D
Hi @Anonymous ,
That's a really elegant solution, thanks for improving mine massively!
Could you help my understanding of the following part of your code please?
( __rev < 0 ) * __rev
What exactly is happening here and how, or what terms should I search to learn about this technique please?
Many thanks.
Proud to be a Datanaut!
@Anonymous , @BA_Pete ,
thanks for the replies guys - i'm using darlove's method yet its still not summing the group right. When I put it into practice I show that its ignoring the positive values in the overall number and just adding up the negatives. So for one of my columns for example its showing -2500 for the actual value but with this calc - it shows -2800 because its ignoring the +300 that went into the overall number. Thoughts?
@BA_Pete , @Anonymous , All.....
Any thoughts on this? Still unable to figure a way to sum up the grouping once I have set it to zero. Following your code it still sums up the overall group and ignores how we set some to zero for being positive numbers. Any thoughts would be greatly appreciated!
YB
Proud to be a Datanaut!