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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.