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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Subtracting the sum of filtered values in one column

Hello,

 

I need do select two cenarios in ONE filter and have the subtraction of the sum of each of then.

Like, if I select A and B, it would be (1+2+3)-(4+5) = -3

Thanks!

 

CenarioValue
A1
A2
A3
B4
B5
C6
C6
1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi  @Anonymous , 

You need to change something in @amitchandak 's expression, you could try below expression 

Measure =
VAR _min =
    MINX ( 'Table', 'Table'[Cenario] )
VAR _max =
    MAXX ( 'Table', 'Table'[Cenario] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Cenario] = _min )
    )
        - CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Cenario] = _max )
        )

You could refer to my sample for details.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
dax
Community Support
Community Support

Hi  @Anonymous , 

You need to change something in @amitchandak 's expression, you could try below expression 

Measure =
VAR _min =
    MINX ( 'Table', 'Table'[Cenario] )
VAR _max =
    MAXX ( 'Table', 'Table'[Cenario] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Cenario] = _min )
    )
        - CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Cenario] = _max )
        )

You could refer to my sample for details.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Try like

Measure =
 var _min = minx(Table,Table[Cenario])
 var _max = maxx(Table,Table[Cenario])
 return 
 calculate(Table[Value],filter(all(Table),Table[Cenario]=_min))- calculate(Table[Value],filter(all(Table),Table[Cenario]=_max))
 

or

  Measure =
 var _min = minx(Table,Table[Cenario])
 var _max = maxx(Table,Table[Cenario])
 return 
 calculate(Table[Value],filter(allselected(Table),Table[Cenario]=_min))- calculate(Table[Value],filter(allselected(Table),Table[Cenario]=_max))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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