Forum Discussion

dragonus's avatar
dragonus
Helper III
6 years ago
Solved

Finding the difference for a long table

I am trying to create a measure to find the difference across dates between 2 different categories in the same Long Table... I tried sum(ValueA) - sum(ValueB), but it doesn't work

 

Sample Table:

 

DateCategoryValue
1/1/19A29
1/1/19B23
2/1/19A35
2/1/19B123
3/1/19A4
3/1/19B2123
4/1/19A445
4/1/19B32

 

So the measure should be able to have A - B for all dates, so for 1/1/19, it should give me 7 (29 - 23)

  • dragonus ,

    measure = calculate(sum(Table[Value]), Table[Category]="A") - calculate(sum(Table[Value]), Table[Category]="B")

  • Hi dragonus ,

     

    You could create a new column to get negative values.

    Column =
    IF ( 'Table'[Category] = "A", 'Table'[Value], - 'Table'[Value] )

    Then create a measure:

    Measure =
    CALCULATE ( SUM ( 'Table'[Column] ), ALLEXCEPT ( 'Table', 'Table'[Date] ) )

     

2 Replies

  • dragonus ,

    measure = calculate(sum(Table[Value]), Table[Category]="A") - calculate(sum(Table[Value]), Table[Category]="B")

  • v-eachen-msft's avatar
    v-eachen-msft
    Community Support

    Hi dragonus ,

     

    You could create a new column to get negative values.

    Column =
    IF ( 'Table'[Category] = "A", 'Table'[Value], - 'Table'[Value] )

    Then create a measure:

    Measure =
    CALCULATE ( SUM ( 'Table'[Column] ), ALLEXCEPT ( 'Table', 'Table'[Date] ) )