Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mr_dj_mcintosh
Regular Visitor

DAX code to calculate year on year percentage change measure for each item in another column

Hi there

 

I have 3 columns of data 'Date', 'Institution', and 'Sales'. I am wanting to calculate a measure that give the year on year % change in sales for each institution.

 

I have been using quick measure for year over year change functin for aggregate sales, but having an issue with finding code that incorporates another column, (i.e. instituion) so as to present % changes for each institution year on year.

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

The general structure for YoY % change calculations is as follows:

VAR LastYear = CALCULATE ( selectedmeasure(), SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) ) RETURN DIVIDE(selectedmeasure()-LastYear,LastYear)

 This is an calculation group example so replace "selectedmeasure" with yout calculation logic. So for example something like SUM('Sales'[values]). If your Sales table has a relationship to 'instittututions' and 'calendar' this code should also account for those dimensions.


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
mr_dj_mcintosh
Regular Visitor

Thanks for your response. Although this calculation is returning all YoY% figures as 0.00%.

 

This is the code I used.  

YOY% Gross earned premium =
VAR __PREV_YEAR =
    CALCULATE(
        SUM('BS_Data_C'[Gross earned premium]),
        SAMEPERIODLASTYEAR ('Date Table'[Date])
    )
RETURN
    DIVIDE(
        SUM('BS_Data_C'[Gross earned premium]) - __PREV_YEAR,
        __PREV_YEAR
    )
 
And a sample of the output.
mr_dj_mcintosh_0-1688720361647.png

 

ValtteriN
Super User
Super User

Hi,

The general structure for YoY % change calculations is as follows:

VAR LastYear = CALCULATE ( selectedmeasure(), SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) ) RETURN DIVIDE(selectedmeasure()-LastYear,LastYear)

 This is an calculation group example so replace "selectedmeasure" with yout calculation logic. So for example something like SUM('Sales'[values]). If your Sales table has a relationship to 'instittututions' and 'calendar' this code should also account for those dimensions.


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks for your response ValtteriN. Although this calculation is returning all YoY% figures as 0.00%.

 

This is the code I used.  

YOY% Gross earned premium =
VAR __PREV_YEAR =
    CALCULATE(
        SUM('BS_Data_C'[Gross earned premium]),
        SAMEPERIODLASTYEAR ('Date Table'[Date])
    )
RETURN
    DIVIDE(
        SUM('BS_Data_C'[Gross earned premium]) - __PREV_YEAR,
        __PREV_YEAR
    )
 
And a sample of the output.
mr_dj_mcintosh_0-1688965269378.png

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.