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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
prasadhebbar315
Advocate I
Advocate I

Average Interactions based on historical dates

Hello everyone,

I have data with Date, Day and Interactions. 

The interactions are spread accross weeks and I am looking for a mesaure to caluclate average interactons based on day (Monday, Tuesday etc..) for the last 4 weeks. In the below table I have data from 06/26 (Monday) till 07/23(Sunday). I need a measure to automatically calculate Monday average based on last 4 mondays interactions. That is (100+104+122+104)/4 = 108. Likewise it has to clauclate last 4 weeks average for Tuesday, Wednesday ...Sunday. When the new week arrives, the calculation has to shift by 1 week to pick up last 4 weeks average. Any help is appreciated.

 

DateDayInteractionsDesired_Output
6/26/2023Monday100108
6/27/2023Tuesday8995
6/28/2023Wednesday6379
6/29/2023Thursday7272
6/30/2023Friday3355
7/1/2023Saturday2028
7/2/2023Sunday1014
7/3/2023Monday104 
7/4/2023Tuesday93 
7/5/2023Wednesday88 
7/6/2023Thursday72 
7/7/2023Friday60 
7/8/2023Saturday30 
7/9/2023Sunday15 
7/10/2023Monday122 
7/11/2023Tuesday101 
7/12/2023Wednesday75 
7/13/2023Thursday63 
7/14/2023Friday55 
7/15/2023Saturday32 
7/16/2023Sunday12 
7/17/2023Monday104 
7/18/2023Tuesday98 
7/19/2023Wednesday90 
7/20/2023Thursday80 
7/21/2023Friday70 
7/22/2023Saturday30 
7/23/2023Sunday18 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@prasadhebbar315 , Create a date table, join with date of you table, have this columns in date Table

 

Have these new columns in Date Table, Week Rank is Important in Date/Week Table

WeekDay = weekday([Date],2)

 

Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX('Date','Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

Last 4 weeks = CALCULATE(Averagex(Values('Date'[Week Rank]), calculate(sum('Table'[Interactions]))) , FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-3 && 'Date'[Week Rank]<=max('Date'[Week Rank]) && 'Date'[WeekDay] =max('Date'[WeekDay ] )))

 

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@prasadhebbar315 , Create a date table, join with date of you table, have this columns in date Table

 

Have these new columns in Date Table, Week Rank is Important in Date/Week Table

WeekDay = weekday([Date],2)

 

Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX('Date','Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

Last 4 weeks = CALCULATE(Averagex(Values('Date'[Week Rank]), calculate(sum('Table'[Interactions]))) , FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-3 && 'Date'[Week Rank]<=max('Date'[Week Rank]) && 'Date'[WeekDay] =max('Date'[WeekDay ] )))

 

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks , the solution has worked...

Hi @amitchandak What is Week Start Date in this calculation? Is it adding row numbers based on first and last date?

Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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