Forum Discussion
Moving Average by Ranked Index
- 3 years ago
Here is your code...
90 Day Average = VAR sDate = MAX('Table2'[Date]) VAR bDate = sDate-90 VAR sValue = CALCULATE(AVERAGE('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate)) RETURN sValueChange the "Calculate(Average" to a Max or Min for the other two measures and get the MAX Date.
90 Min = VAR sDate = MAXX(ALL('Table2'[Date]),'Table2'[Date]) VAR bDate = sDate-90 VAR sValue = CALCULATE(MIN('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate)) RETURN sValue
Here is your code...
90 Day Average =
VAR sDate = MAX('Table2'[Date])
VAR bDate = sDate-90
VAR sValue = CALCULATE(AVERAGE('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate))
RETURN sValue
Change the "Calculate(Average" to a Max or Min for the other two measures and get the MAX Date.
90 Min =
VAR sDate = MAXX(ALL('Table2'[Date]),'Table2'[Date])
VAR bDate = sDate-90
VAR sValue = CALCULATE(MIN('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate))
RETURN sValue
Thank you!
Would you mind posting your power bi file or picture of your data model for me to replicate. I am having issues getting it to work on my end?
- BrianConnelly3 years ago
Resolver III
I didn't use a data model, just made a copy of your posted data.
The measures are posted in previous. If you have a date table with a relationship then switch out the date fields in the measure with the date fields of the date table.
Also, check your data types, i.e. Date fields are of data type Date. Numbers are of data type Whole or Decimal, etc.