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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Getting difference between this week's average and last week's average

Hi I am new and this is meant to be a very easy task but for some reason I've spent hours on it with no result???

 

All I want is the difference between this week's average and last week's average.

 

Sample table:

 

WeekendPrice
28/12/20191
28/12/20191
28/12/20191
21/12/20193
21/12/20191
21/12/20192
14/12/20194
14/12/20191
14/12/20191
14/12/20194

 

So the answer I am expecting is (1+1+1)/3 - (3+1+2)/3 = -1

 

I tried to google but came up with rankx and really complicated measures which I don't understand...

 

Any help would be appreciated

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

You can break this problem down into a number of smaller steps using variables. So you can calculate the current week date, the prior week date and then the averages for those 2 dates.

 

The following expression should give you the answer you are after based on your sample data

Change from Prior Week Avg = 
var _currentWeek = max('Table'[Weekend])
var _priorWeek = maxx(filter(all('Table'[Weekend]), 'Table'[Weekend] < _currentWeek), 'Table'[Weekend])
var _currentAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _currentWeek), 'Table'[Price])
var _priorAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _priorWeek), 'Table'[Price])
return if(ISBLANK(_priorAvg),blank(), _currentAvg - _priorAvg)

View solution in original post

5 REPLIES 5
d_gosbell
Super User
Super User

You can break this problem down into smaller pieces using variables. So you can get the current week date, the prior week date and the averages for those two dates.

 

An expression like the follow will give you the answer you are after based on your sample data

 

 

 

Change from Prior Week Avg = 
var _currentWeek = max('Table'[Weekend])
var _priorWeek = maxx(filter(all('Table'[Weekend]), 'Table'[Weekend] < _currentWeek), 'Table'[Weekend])
var _currentAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _currentWeek), 'Table'[Price])
var _priorAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _priorWeek), 'Table'[Price])
return if(ISBLANK(_priorAvg),blank(), _currentAvg - _priorAvg)

 

 

 

 

d_gosbell
Super User
Super User

You can break this problem down into smaller pieces using variables. So you can get the current week date, the prior week date and the averages for those two dates.

 

An expression like the follow will give you the answer you are after based on your sample data

 

 

Change from Prior Week Avg = 
var _currentWeek = max('Table'[Weekend])
var _priorWeek = maxx(filter(all('Table'[Weekend]), 'Table'[Weekend] < _currentWeek), 'Table'[Weekend])
var _currentAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _currentWeek), 'Table'[Price])
var _priorAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _priorWeek), 'Table'[Price])
return if(ISBLANK(_priorAvg),blank(), _currentAvg - _priorAvg)

 

 

 

d_gosbell
Super User
Super User

You can break this problem down into smaller pieces using variables. So you can get the current week date, the prior week date and the averages for those two dates.

 

An expression like the follow will give you the answer you are after based on your sample data

 

Change from Prior Week Avg = 
var _currentWeek = max('Table'[Weekend])
var _priorWeek = maxx(filter(all('Table'[Weekend]), 'Table'[Weekend] < _currentWeek), 'Table'[Weekend])
var _currentAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _currentWeek), 'Table'[Price])
var _priorAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _priorWeek), 'Table'[Price])
return if(ISBLANK(_priorAvg),blank(), _currentAvg - _priorAvg)

 

 

d_gosbell
Super User
Super User

You can break this problem down into smaller pieces using variables. So you can get the current week date, the prior week date and the averages for those two dates.

 

An expression like the follow will give you the answer you are after based on your sample data

Change from Prior Week Avg = 
var _currentWeek = max('Table'[Weekend])
var _priorWeek = maxx(filter(all('Table'[Weekend]), 'Table'[Weekend] < _currentWeek), 'Table'[Weekend])
var _currentAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _currentWeek), 'Table'[Price])
var _priorAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _priorWeek), 'Table'[Price])
return if(ISBLANK(_priorAvg),blank(), _currentAvg - _priorAvg)

 

d_gosbell
Super User
Super User

You can break this problem down into a number of smaller steps using variables. So you can calculate the current week date, the prior week date and then the averages for those 2 dates.

 

The following expression should give you the answer you are after based on your sample data

Change from Prior Week Avg = 
var _currentWeek = max('Table'[Weekend])
var _priorWeek = maxx(filter(all('Table'[Weekend]), 'Table'[Weekend] < _currentWeek), 'Table'[Weekend])
var _currentAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _currentWeek), 'Table'[Price])
var _priorAvg = AVERAGEX(filter(all('Table'), 'Table'[Weekend] = _priorWeek), 'Table'[Price])
return if(ISBLANK(_priorAvg),blank(), _currentAvg - _priorAvg)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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