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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
ashear
New Member

How to calculate a sum of certain values created in a measure

Hi all! I am new to power Bi and could really use some help!

I have created calculated measures in Power BI which sum the "LY units" and "TY Units" based on a date range from my raw sales table.

I then created another measure which calculated the difference in units from LY/TY.

Now what I am trying to do is to get to two separete sums:

One sum of all the total positive "gain" unit differences to get a "Total Gain"
and one sum of all the total negative "Drain" unit differences to get a "Total Drain".

I cant seem to find a way to SUMX a measure, or even how to SUMX a measure and filter it to <0 or >0.

When we get those totals we would like to be able to bounce the TY/LY unit diff number against the "Total Gain" and "Total Drain" to know what part numbers are contributing the most to the drain and/or gain.

Here is a screenshot of how I can get those calculation in Excel, just trying to figure out how to get them in Power BI via DAX now.

 

Highlighted in green is the formuals I am trying to figure out

 

ashear_1-1754597846410.png

ashear_2-1754597888411.png

 

 

1 ACCEPTED SOLUTION
Irwan
Super User
Super User

hello @ashear 

 

here is the DAX for SUMX <0 and >0

- SUMX<0

Irwan_0-1754605295258.png

Adding divide to get the result above

Irwan_2-1754605425787.png

 

- SUMX>0

Irwan_1-1754605312641.png

adding divide to get above result

Irwan_3-1754605445799.png

 

Else, tweak a little bit if you need in measure form.

Irwan_4-1754605566861.png

Irwan_5-1754605584376.png

 

Hope this will help.

Thank you.

 

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Does this measure work

Gains = SUMX(filter(VALUES(Data[Partno]),[Diff]>0),[Diff])

Losses = SUMX(filter(VALUES(Data[Partno]),[Diff]<0),[Diff])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Irwan
Super User
Super User

hello @ashear 

 

here is the DAX for SUMX <0 and >0

- SUMX<0

Irwan_0-1754605295258.png

Adding divide to get the result above

Irwan_2-1754605425787.png

 

- SUMX>0

Irwan_1-1754605312641.png

adding divide to get above result

Irwan_3-1754605445799.png

 

Else, tweak a little bit if you need in measure form.

Irwan_4-1754605566861.png

Irwan_5-1754605584376.png

 

Hope this will help.

Thank you.

 

Thank you Irwan! That did the trick, I think where I was having trouble was I wasnt refrencing the table and the measure, just trying to do the measure, which ment certain data fields werent showing up!

hello @ashear 

 

glad to be a help.

Thank you.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.