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
ahammond01
Frequent Visitor

Percent Change of Previous 3 month period compared to current month

Hi, 

 

I would like to be able to calculate the percentage change of the car registrations during the previous 3 months compared to the current month's data. 

 

I am very new to DAX, so I will just show you an example of how I used to calculate this when doing it in excel. My sample data is below as well.

 

Percentage change= (Current Month-Prior 3 Month Average)/ (Prior 3 Month Average)

EX: Percentage change for Brazil= (157-average(147,136,189))/average(147,136,189).

 

each month I will be adding the latest month's data to this list, so it would be great if this could auto- adjust to the previous 3 months vs the current month values. 

 

CountryDate AddedCar Registrations
Brazil2/17/2017 147 
Brazil3/17/2017 136 
Brazil4/17/2017 189 
Brazil5/17/2017 157 
Canada2/17/2017 128 
Canada3/17/2017 113 
Canada4/17/2017 125 
Canada5/17/2017 191 
China2/17/2017 2,218 
China3/17/2017 1,633 
China4/17/2017 2,096 
China5/17/2017 1,722 
Euro Area2/17/2017 895 
Euro Area3/17/2017 900 
Euro Area4/17/2017 908 
Euro Area5/17/2017 904 
India2/17/2017 244 
India3/17/2017 240 
India4/17/2017 263 
India5/17/2017 254 
Indonesia2/17/2017 100 
Indonesia3/17/2017 87 
Indonesia4/17/2017 95 
Indonesia5/17/2017 101 

 

Does anyone have any ideas for how to do this?

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@ahammond01

 

Hi let's go to find a solution:

 

Create these measures

 

 

CurrentMonth =
VAR CMonth =
    MONTH ( LASTDATE ( Table1[Date Added] ) )
RETURN
    CALCULATE (
        SUM ( Table1[Car Registrations] ),
        FILTER ( Table1, MONTH ( Table1[Date Added] ) = CMonth )
    )

 

Average3MonthsPrev =
CALCULATE (
    AVERAGE ( Table1[Car Registrations] ),
    DATESBETWEEN (
        Table1[Date Added],
        STARTOFMONTH ( DATEADD ( LASTDATE ( Table1[Date Added] ), -4, MONTH ) ),
        ENDOFMONTH ( DATEADD ( LASTDATE ( Table1[Date Added] ), -1, MONTH ) )
    )
)
PercentageChange =
DIVIDE ( [CurrentMonth] - [Average3MonthsPrev], [Average3MonthsPrev], 0 )

Image.png

Let me know if works in your scenario.

 

 




Lima - Peru

View solution in original post

3 REPLIES 3
Vvelarde
Community Champion
Community Champion

@ahammond01

 

Hi let's go to find a solution:

 

Create these measures

 

 

CurrentMonth =
VAR CMonth =
    MONTH ( LASTDATE ( Table1[Date Added] ) )
RETURN
    CALCULATE (
        SUM ( Table1[Car Registrations] ),
        FILTER ( Table1, MONTH ( Table1[Date Added] ) = CMonth )
    )

 

Average3MonthsPrev =
CALCULATE (
    AVERAGE ( Table1[Car Registrations] ),
    DATESBETWEEN (
        Table1[Date Added],
        STARTOFMONTH ( DATEADD ( LASTDATE ( Table1[Date Added] ), -4, MONTH ) ),
        ENDOFMONTH ( DATEADD ( LASTDATE ( Table1[Date Added] ), -1, MONTH ) )
    )
)
PercentageChange =
DIVIDE ( [CurrentMonth] - [Average3MonthsPrev], [Average3MonthsPrev], 0 )

Image.png

Let me know if works in your scenario.

 

 




Lima - Peru

Is there a way to update the Current Month and Average measure so that it picks up the last date for each country? For example, sometimes a few countries have not made an update to their data in a few months so we may be in June for other months but their data only goes up to February. In that case the formula does not work. 

 

Here's an example: 

 

CountryDate AddedCar Registrations
Thailand1/17/2017 32 
Thailand2/17/2017 35 
Thailand3/17/2017 41 
Thailand4/17/2017 27 
United States11/17/2016 488 
United States12/17/2016 554 
United States1/17/2017 441 
United States2/17/2017 502 

 

For the US... here is what I get using the measures in the previous message: 

 

Capture.PNG  But it should be 502 current month and 494.33 for the average so a 1.5%  change. (502-494.33)/494.33

 

 

This worked Perfectly!!! Thank you so much.

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.