Forum Discussion

CleliaComes's avatar
CleliaComes
Helper I
5 years ago
Solved

Matrix – percent change between columns

Hi   Is there a DAX formula to calculate and display the % change in a matrix between the months? To make it more clear, I added my file, pls click here.   Kind regards, Clélia
  • DataZoe's avatar
    5 years ago

    CleliaComes This measure should give you the percent difference between your months:

     

    Percent Difference =
    VAR thisMonth =
    SUM ( 'GL PL'[Saldi resultaat] )
    VAR lastMonth =
    CALCULATE ( SUM ( 'GL PL'[Saldi resultaat] ), PREVIOUSMONTH ( Kalender[Date] ) )
    RETURN
    IF (
    OR ( ISBLANK ( thisMonth ), ISBLANK ( lastMonth ) ),
    BLANK (),
    DIVIDE ( thisMonth - lastMonth, lastMonth )
    )

     

     

  • DataZoe's avatar
    DataZoe
    5 years ago

    CleliaComes I think there are two parts here!  

    1. Showing the percentage including a previous month that may be filtered out (such as if you have December 2020 and only showing 2021 -- we want to show that January 2021 percent difference from December 2020). That can be resolved with this modification:

     

    Percent Difference =
    VAR thisMonth =
        SUM ( 'GL PL'[Saldi resultaat] )
    VAR lastMonth =
        CALCULATE (
            SUM ( 'GL PL'[Saldi resultaat] ),
            ALL ( Kalender ),
            PREVIOUSMONTH ( Kalender[Date] )
        )
    RETURN
        IF (
            OR ( ISBLANK ( thisMonth )ISBLANK ( lastMonth ) ),
            BLANK (),
            DIVIDE ( thisMonth - lastMonthlastMonth )
        )
     
    2. The second is adjusting the matrix formatting a little. To have it take up less space I would first try simply renaming the "Perecent Difference" to "%" or something small so it doesn't take up so much space. 


    The second approach is to create a new measure that joins the value in a more meaningful way into a single column, such as this:

     

    Matrix Values =
    -- If the value is blank, return blank, otherwise return it formatted as a whole number
    IF (
        ISBLANK ( SUM ( 'GL PL'[Saldi resultaat] ) ),
        BLANK (),
        FORMAT ( SUM ( 'GL PL'[Saldi resultaat] )"#,##0" )
    ) -- If the percenage difference is blank, return blank, otherwise return the percentage appended
    -- to the number in the right format as well as a +/- sign in ()s.
        IF (
            ISBLANK ( [Percent Difference] ),
            BLANK (),
            " ("
                IF ( [Percent Difference] > 0"+""" )
                FORMAT ( [Percent Difference], "Percent" ) & ")"
        )