Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Help to calculate the difference between two years

Hi,
 
Would really appreciate any help. I'm still learning Power BI and struggling to create a card which shows the difference in the average % from 2020 and 2015.
 
I've tried a couple methods including one with a single formula and the other with several measures from another solution posted. Unfortunately I couldn't get both to work.
1. Measures:
2014 Average = CALCULATE(AVERAGE('Strategic Projects'[Local Content (%)]),'Calendar'[Date]="2014")
2020 Average = CALCULATE(AVERAGE('Strategic Projects'[Local Content (%)]),'Calendar'[Date]="2020")
2020 to 2014 difference = [2020 Average]-[2014 Average]

2. Other method tried:
Difference 2020 to 2015 = [Local Content Average],YEAR([Date signed or approved]=2020) - [Local Content Average],YEAR([Date signed or approved]=2015)
 
Would you have some suggestions on how I can fix my approach to this?


Thanks!
Brendan
  • Anonymous , In case you have selected a year or something from calendar table , then prefer to use all in calendar filter

     

    2014 Average = CALCULATE(AVERAGE('Strategic Projects'[Local Content (%)]),filter(all('Calendar'),'Calendar'[Date]="2014"))


    2020 Average = CALCULATE(AVERAGE('Strategic Projects'[Local Content (%)]),filter(all('Calendar'),'Calendar'[Date]="2014"))


    2020 to 2014 difference = [2020 Average]-[2014 Average]

2 Replies

  • Anonymous , In case you have selected a year or something from calendar table , then prefer to use all in calendar filter

     

    2014 Average = CALCULATE(AVERAGE('Strategic Projects'[Local Content (%)]),filter(all('Calendar'),'Calendar'[Date]="2014"))


    2020 Average = CALCULATE(AVERAGE('Strategic Projects'[Local Content (%)]),filter(all('Calendar'),'Calendar'[Date]="2014"))


    2020 to 2014 difference = [2020 Average]-[2014 Average]

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous  ,

    According to your description, data was created from 2014 to 2020:

    Here are the steps you can follow:

    1. Create calaculated column.

    Year = YEAR('Table'[Date])

    2. Create measure.

    avg_year =
    var _firstyear=MIN('Table'[Year])
    var _lastyear=MAX('Table'[Year])
    return
    CALCULATE(AVERAGE('Table'[amount]),ALLEXCEPT('Table','Table'[Year]),FILTER('Table','Table'[Year]=_firstyear))
    -
    CALCULATE(AVERAGE('Table'[amount]),ALLEXCEPT('Table','Table'[Year]),FILTER('Table','Table'[Year]=_lastyear))

    3. Result

    Put the year field in the slicer, and set the AVG_ Year is put into the card, two years are selected in the slicer, and the average value of these two years is shown in the card

    You can downloaded PBIX file from here.

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.