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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
romoguy15
Helper IV
Helper IV

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
V-pazhen-msft
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
V-pazhen-msft
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.

 

V-pazhen-msft
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.

amitchandak
Super User
Super User

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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