cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper II
Helper II

Calculate Average Tickets in the Last 4 Weeks using VAR

Hello,

 

I am looking to figure out a calulation that can average out the ticket count within the last 4 weeks referring back to the current date.  In my sample data, I have already figured out a method, but it doesn't seem to be the best way in my opinion. So in my mind, the calulation should be something like averagex, but referring to a VAR going back to the last 4 weeks. In my sample data, I also have a fiscal calendar showing the fiscal week number. 

 

 

I have some sample data posted in the link below.
https://1drv.ms/u/s!AqID1H0nHPOzg3iZ797Q6uCBtmV9?e=8RbbLj

1 ACCEPTED SOLUTION
Community Support
Community Support

@romoguy15 


I guess 52.50 is the correct expected result. You cannot use dates function because the fiscal week is custom assigned start from Feb. So you can only filter the fiscal week column with custom expression.

ast 4 Wks Ave Tickets per Week = CALCULATE(
AVERAGEX(VALUES( 'Calendar'[Fiscal Week] ), [Total Tickets] ),
FILTER('Calendar',
          'Calendar'[Fiscal Week]<CALCULATE(MAX('Calendar'[Fiscal Week]),FILTER('Calendar',[Date]=TODAY())) 
                && 'Calendar'[Fiscal Week]>=CALCULATE(MAX('Calendar'[Fiscal Week]),FILTER('Calendar',[Date]=TODAY()))-4))

 

V-pazhen-msft_0-1606789373067.png


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
Community Support
Community Support

@romoguy15 


I guess 52.50 is the correct expected result. You cannot use dates function because the fiscal week is custom assigned start from Feb. So you can only filter the fiscal week column with custom expression.

ast 4 Wks Ave Tickets per Week = CALCULATE(
AVERAGEX(VALUES( 'Calendar'[Fiscal Week] ), [Total Tickets] ),
FILTER('Calendar',
          'Calendar'[Fiscal Week]<CALCULATE(MAX('Calendar'[Fiscal Week]),FILTER('Calendar',[Date]=TODAY())) 
                && 'Calendar'[Fiscal Week]>=CALCULATE(MAX('Calendar'[Fiscal Week]),FILTER('Calendar',[Date]=TODAY()))-4))

 

V-pazhen-msft_0-1606789373067.png


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

Community Support
Community Support

@romoguy15 
-28 days  is one the correct option to filter. But the confusion is what do you mean by last 4 weeks from current date. It has to be very clear.

 

Do you mean last 3 week + this week until today(if today is 40 week's Wednesday, you want  37,38,39, 40 until Wednesday OR last 4 weeks excluding this week (if this week is 40, you want 36,37,38,39).

 

Paul

Hello Paul, it would be last 4 weeks excluding this week. Sorry for not explaining clearly. I know that the way I currently have it calculated is not correct since I am counting back 28 days. But the ideal and correct method of what I would like is last 4 weeks excluding this week.

Super User IV
Super User IV

@romoguy15 , refer if my week vs week blog can help

Columns

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)

 

measures
This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))
Last 8 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-8 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

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...

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors