Forum Discussion
Max of rolling average expression
- 3 years ago
Hi,
These measures work
TL = SUM('RPE/Wellness'[Training Load])TL in previous week = CALCULATE([TL],DATESBETWEEN('Date'[Date],MIN('Date'[Date])-6,min('Date'[Date])))7 day rolling average = if(ISBLANK([TL]),BLANK(),DIVIDE([TL in previous week],7))All time high rolling average = if(ISBLANK([TL]),BLANK(),MAXX(ALL('Date'),[7 day rolling average]))Also, to the visul, drag Date from the Date Table.
Hope this helps.
- 3 years ago
Hi big_ozzie1
This time I totalled the Training Load for the last 7 days and divided it by 7. (It appears to be what you were doing with your [7dayRA] only using a date table to account for missing dates.)
My RA = VAR _CurrDt = SELECTEDVALUE( 'Date'[Date] ) VAR _LastWk = _CurrDt - 7 VAR _SumOfLastWk = CALCULATE( [Total], FILTER( ALL( 'Date'[Date] ), 'Date'[Date] > _LastWk && 'Date'[Date] <= _CurrDt ) ) RETURN _SumOfLastWk / 7(Note: Looking at rolling totals sorted descendingly seems to be counter-intuitive for me. If it was me, I'd only look at the dates in a descending order AFTER I was convinced they worked in ascending order. But that's just my opinion.)
pbix: Help - mine.pbix
Let me know how this goes.
(Also, my apologies to Ashish_Mathur since I had came up with my solution last night I didn't see your almost identical solution. )
big_ozzie1 , You should always use date table in such cases. Try like
7dayRA =
VAR numdays = 7
return CALCULATE(AVERAGEX(Values(Date[Date]), calculate(SUM('RPE/Wellness'[Training Load]))),DATESINPERIOD('Date'[date], Max('Date'[date]),-numdays, DAY))
Thanks very much for the response. This works with the MAXX function, but unfortunately your rolling average calculation does not take null days into account. The application here is sports, so I need to account for days with no data as well.
For example, for this table, the 7-day rolling average should be 111.43. With yours it is 260.
| Date | Training Load |
| 8/8/2022 | 300 |
| 8/7/2022 | |
| 8/6/2022 | 240 |
| 8/5/2022 | |
| 8/4/2022 | 240 |
| 8/3/2022 | |
| 8/2/2022 |
Is there any way around the blank data issue? Thanks!
- grantsamborn3 years agoSolution Sage
Hi big_ozzie1
Would something like this help?
Total = SUM( 'RPE/Wellness'[Training Load] ) My RA = VAR _Days = 7 VAR _CurrDt = SELECTEDVALUE( 'Date'[Date] ) VAR _LastWk = _CurrDt - _Days VAR _Result = AVERAGEX( FILTER( ALL( 'Date'[Date] ), 'Date'[Date] >= _LastWk && 'Date'[Date] <= _CurrDt ), [Total] ) RETURN _Result / _Days Max of RA = MAXX( ALL( 'Date'[Date] ), [My RA] )In this pbix, I looked at 2 different methods. (I originally thought that you weren't worried about the dates with no values.)
pbix: MAX of 7-day Rolling Average.pbix
- big_ozzie13 years agoFrequent Visitor
Hi grantsamborn
Thank you as well for the help. This is very close. You will see below your rolling average output (My RA) versus desired (7dayRA):
Your rolling average values mostly divide evenly into the desired values, strangely. One would think this observation would result in a speedy fix, though it appears I'm not yet savvy enough to figure out what's going on. Maybe you can figure it out?
- grantsamborn3 years agoSolution Sage
Let's start at the beginning.
Can you show the following?
1) Please provide sample data that covers your issue or question completely.
(I hate retyping sample data.)
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...2) Please show the expected outcome based on the sample data you provided.
https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/14475233) Please explain how you would expect to get from 1) to 2).
I would like to see a) your expected result AND b) how you intend to use it.