Forum Discussion
Calculate with Datesbetween filter and another filter
- 6 years ago
Hi mws5872 ,
It's not sure if the results in the sample data you gave are correct. You can try to create the following measures
2 day sum = CALCULATE ( SUM ( Data[Total] ), DATESINPERIOD ( Data[Date], LASTDATE ( Data[Date] ), -2, DAY ) ) 2 days avg = [2 day sum]/2 comparison = VAR this_weekday = SELECTEDVALUE ( Data[Day of Wek Number] ) VAR last_weekday = CALCULATE ( MAX ( Data[Day of Wek Number] ), FILTER ( ALL ( Data ), Data[Date] = SELECTEDVALUE ( Data[Date] ) - 1 ) ) VAR avg_static = CALCULATE ( AVERAGE ( Data[Total] ), FILTER ( ALL ( Data ), Data[Date] >= DATE ( 2020, 2, 9 ) && Data[Date] <= DATE ( 2020, 3, 8 ) && Data[Day of Wek Number] IN { this_weekday, last_weekday } ) ) RETURN DIVIDE ( [2 days avg], avg_static )Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
mws5872 ,not very clear. But in can you need rolling week data refer
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-Last-Week/ba-p/1051123
amitchandak not exactly solved by this. Here are some things I have tried.
1. hard coding dates between. I even created a field in SQL that only has data for the dates mentioned.
I tried this
SWITCH(VALUES('Date'[Weekday]),7,CALCULATE(Average(Volume[Total]),FILTER('Date','Date'[Weekday]<=7&& 'Date'[Weekday] >1)),
2,CALCULATE(Average(Volume[Total]),FILTER('Date','Date'[Weekday]=2)),
3,CALCULATE(Average(Volume[Total]),FILTER('Date','Date'[Weekday]<=3&& 'Date'[Weekday] >1)),
4,CALCULATE(Average(Volume[Total]),FILTER('Date','Date'[Weekday]<=4&& 'Date'[Weekday] >1)),
5,CALCULATE(Average(Volume[Total]),FILTER('Date','Date'[Weekday]<=5&& 'Date'[Weekday] >1)),
6,CALCULATE(Average(Volume[Total]),FILTER('Date','Date'[Weekday]<=6&& 'Date'[Weekday] >1)),
1,CALCULATE(Average(Volume[Total]),FILTER('Date','Date'[Weekday]<=7)))
- V-lianl-msft6 years agoCommunity Support
Hi mws5872 ,
It's not sure if the results in the sample data you gave are correct. You can try to create the following measures
2 day sum = CALCULATE ( SUM ( Data[Total] ), DATESINPERIOD ( Data[Date], LASTDATE ( Data[Date] ), -2, DAY ) ) 2 days avg = [2 day sum]/2 comparison = VAR this_weekday = SELECTEDVALUE ( Data[Day of Wek Number] ) VAR last_weekday = CALCULATE ( MAX ( Data[Day of Wek Number] ), FILTER ( ALL ( Data ), Data[Date] = SELECTEDVALUE ( Data[Date] ) - 1 ) ) VAR avg_static = CALCULATE ( AVERAGE ( Data[Total] ), FILTER ( ALL ( Data ), Data[Date] >= DATE ( 2020, 2, 9 ) && Data[Date] <= DATE ( 2020, 3, 8 ) && Data[Day of Wek Number] IN { this_weekday, last_weekday } ) ) RETURN DIVIDE ( [2 days avg], avg_static )Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.