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
CleliaComes
Helper I
Helper I

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.

 

Power BI example change %.JPG


Kind regards,

Clélia

2 ACCEPTED SOLUTIONS
DataZoe
Employee
Employee

@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_1-1614698806720.png

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

@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. 
DataZoe_1-1614966481404.png

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" ) & ")"
    )
 
DataZoe_2-1614966506116.png

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

9 REPLIES 9
CleliaComes
Helper I
Helper I

Hi @DataZoe 

 

Can I ask you one more question: what if I add new data for a new year for example for '2020' in the same matrix with a slicer? I tried it and then I guess I have to add something to the formula? The year 2020 works - 2021 doens't give any result.

The updated file can be found here Power BI ex 2.JPGPower BI ex 1.JPG

Kr

Clélia

 

@CleliaComes I did notice if your file the Kalendar table is not marked as a date table, so they may impact. The Year should be coming from the Kalendar table too in the above slicer.

 

When I did mark it as a date table, it converted the Date to a date format (removing year and month options), but you can correct for this by adding some columns like so:

 

Kalender =
ADDCOLUMNS (
    CALENDARAUTO (),
    "Month"DATE ( YEAR ( [Date] )MONTH ( [Date] )1 ),
    "Year"DATE ( YEAR ( [Date] )11 ),
    "Week",
        [Date] - WEEKDAY ( [Date], 1 ) + 1,
    "Monthly Week Number",
        WEEKNUM ( [Date], 1 )
            WEEKNUM ( DATE ( YEAR ( [Date] )MONTH ( [Date] )1 )1 ) + 1,
    "Yearly Week Number"WEEKNUM ( [Date] )
)

 

Then you can format your new Year and Month columns. I've included the changes in the attached PBIX.

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Thanks a lot for your help! I will figure it out tomorrow! Regards, Clélia

Hi @DataZoe 

 

It works perfectly! Thanks a lot also to adjust the calendar table! 😀
The only thing is that the first % diff column is empty in the example because there is no data for December 2020. Or when I add 2020, January 2021 % whill shown the diff between December 2020- January 2021. I tried to add a year filter on the visual but that doesn't change anything.  I was looking at the forum how to hide a column in a matrix but that seems not so easy and the solution I found deleted also the result column of January. Do you have any idea? 

kr,

Clélia

CleliaComes_0-1614947643815.png

 

@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. 
DataZoe_1-1614966481404.png

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" ) & ")"
    )
 
DataZoe_2-1614966506116.png

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Thanks a lot for helping me with this matter and all the other extra information! 🙂 It is exactly what I was looking for. 
Regards, 

Clélia

CleliaComes
Helper I
Helper I

Thanks a lot for your quick & clear answer! 
Kr,

Clélia

@CleliaComes You're welcome! Thank you for sharing your file as well!

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

DataZoe
Employee
Employee

@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_1-1614698806720.png

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

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.