Forum Discussion

Raul's avatar
Raul
Post Patron
9 years ago
Solved

Difference between two columns or rows

Hello everybody, I need to find the difference between two columns or two rows within a table or matrix of values. I have the following situation:   YEAR ZONE       EAST W...
  • dkay84_PowerBI's avatar
    9 years ago

    Create a measure called "Difference"

     

    Difference =
    IF (
        HASONEVALUE ( 'Table'[YEAR] ),
        BLANK (),
        CALCULATE (
            SUM ( 'Table'[AMOUNT] ),
            FILTER ( 'Table', 'Table'[YEAR] = MAX ( 'Table'[YEAR] ) )
        )
            - CALCULATE (
                SUM ( 'Table'[AMOUNT] ),
                FILTER ( 'Table', 'Table'[YEAR] = MIN ( 'Table'[YEAR] ) )
            )
    )

    Then a measure called "%Inc"

     

    %Inc =
    DIVIDE (
        [Difference],
        CALCULATE (
            SUM ( 'Table'[AMOUNT] ),
            FILTER ( 'Table', 'Table'[YEAR] = MIN ( 'Table'[YEAR] ) )
        )
    )

    Then just shrink the columns in your matrix that have no data so they don't show up, and make sure to turn the row totals on:

     

    Oh and change the formatting/style for the measures as desired.