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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
amaaiia
Helper V
Helper V

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors