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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
amaaiia
Super User
Super User

Define a measure subtracting two sums depending on one column value

I have a table with the following data:

groupfield1field2field3
A2038
A1625
B1055
B1542
A791

 

I need to define a measure that performs the subtraction of sum(field1)-sum(field3) when group='A' and sum(field2)-sum(field3) when group='B'. How can I achieve this?

 

Something in pseudocode like:

sum(if group='A' then field1 else field2)-sum(field3)

 

With the previous table, the result should be:

(20+16+5+4+7)-(8+5+5+2+1)=52-21=31

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1715096873527.png

 

 

Expected result measure: =
VAR _conditionA =
    FILTER ( data, data[group] = "A" )
VAR _conditionB =
    FILTER ( data, data[group] = "B" )
RETURN
    SUMX ( _conditionA, data[field1] - data[field3] )
        + SUMX ( _conditionB, data[field2] - data[field3] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1715096873527.png

 

 

Expected result measure: =
VAR _conditionA =
    FILTER ( data, data[group] = "A" )
VAR _conditionB =
    FILTER ( data, data[group] = "B" )
RETURN
    SUMX ( _conditionA, data[field1] - data[field3] )
        + SUMX ( _conditionB, data[field2] - data[field3] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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