cancel
Showing results for
Did you mean:
Helper III

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

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))``````

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

4 REPLIES 4
Community Support

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))``````

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

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

Helper III

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

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

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.

Proud to be a Super User!

Announcements