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
Anonymous
Not applicable

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
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@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]

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous  ,

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

v-yangliu-msft_0-1608540690098.png

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

v-yangliu-msft_1-1608540690109.png

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.

amitchandak
Super User
Super User

@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]

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.