Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I been trying to caclulate a moving average ignoring weekend dates. I can't seem to figure out how to combine Datesinperiod() with Filter(). How do i filter the date table and then do the moving average?
My moving average calculation
50SMA =
CALCULATE (
AVERAGEX ( 'Stock Data', 'Stock Data'[price.close]),
DATESINPERIOD (
'Date'[Date],
LASTDATE ( 'Date'[Date] ),
-50,
DAY
)
)
My Filter
FILTER('Date','Date'[WeekdayNum]<>6 && 'Date'[WeekdayNum] <>0)
Solved! Go to Solution.
Create a date column that does no have a weekend , means blank for week end. Create a rank on it. All wek end will get one other date will get rank. You can use now this in place of Date. -50 will give 50 working days . something like
CALCULATE(Average(Sales[Net Sales]),FILTER(all('Date'),'Date'[WorkDayRank]>=min('Date'[WorkDayRank])-50 && 'Date'[WorkDayRank]<=max('Date'[WorkDayRank])))
The problem with this approach is if someone selects week end in calendar/slicer it will not work.
To make that work, you have to fill the weekend with the last working date.
-1 from Saturday date, -2 from Sunday date
This will keep same rank for week end as friday
WorkingDate = if(WEEKDAY('Date'[Date],2)<6,[Date],[Date]-WEEKDAY('Date'[Date],2)+5)
Create a date column that does no have a weekend , means blank for week end. Create a rank on it. All wek end will get one other date will get rank. You can use now this in place of Date. -50 will give 50 working days . something like
CALCULATE(Average(Sales[Net Sales]),FILTER(all('Date'),'Date'[WorkDayRank]>=min('Date'[WorkDayRank])-50 && 'Date'[WorkDayRank]<=max('Date'[WorkDayRank])))
The problem with this approach is if someone selects week end in calendar/slicer it will not work.
To make that work, you have to fill the weekend with the last working date.
-1 from Saturday date, -2 from Sunday date
This will keep same rank for week end as friday
WorkingDate = if(WEEKDAY('Date'[Date],2)<6,[Date],[Date]-WEEKDAY('Date'[Date],2)+5)
Interesting work around. It worked for me.
Thank you very much!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
93 | |
75 | |
62 | |
50 |
User | Count |
---|---|
147 | |
107 | |
105 | |
87 | |
61 |