Forum Discussion
Rolling average Last Month and Current Month
- 3 years ago
Hi Anonymous ,
Sorry about that, try this:myMeasure = VAR _monthNumberCurrent = MAX ( mytable[monthNumber] ) //get the month number from this row var _thisMonthFlag = MAX(myTable[Flag]) VAR _prevMonthNumber = CALCULATE ( MAX ( mytable[monthNumber] ), FILTER ( ALL ( myTable ), myTable[monthNumber] < _monthNumberCurrent ) ) //filter the table to all month numbers less than this month number, and get the max value which is the month before var _lastMonthFlag = CALCULATE(MAX(myTable[Flag]),FILTER(ALL(myTable),myTable[MonthNumber]=_prevMonthNumber)) RETURN DIVIDE ( _thisMonthFlag + _lastMonthFlag, IF(_lastMonthFlag = 0,1,2 ))
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πare nice too.
Nathaniel
Hi Anonymous JohnShepherdAPD ,
If I understand your issue correctly, please try this measure:
myMeasure =
VAR _monthNumberCurrent =
MAX ( mytable[monthNumber] ) //get the month number from this row
VAR _prevMonthNumber =
CALCULATE (
MAX ( mytable[monthNumber] ),
FILTER ( ALL ( myTable ), myTable[monthNumber] < _monthNumberCurrent )
) //filter the table to all month numbers less than this month number, and get the max value which is the month before
RETURN
DIVIDE ( _monthNumberCurrent + _prevMonthNumber, 2 )
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πare nice too.
Nathaniel
Hi Nathaniel_C ,
Thanks for this.
I am actually looking for average of [Flag] on those months ...
In the timeline on the right bottom corner ...
For February: it should be (5+4) / 2 = 4.5
For March: (4+3)/2 = 3.5
The final measure will be 2 months rolling average ...
Many thanks
- Nathaniel_C3 years agoCommunity Champion
Hi Anonymous ,
Sorry about that, try this:myMeasure = VAR _monthNumberCurrent = MAX ( mytable[monthNumber] ) //get the month number from this row var _thisMonthFlag = MAX(myTable[Flag]) VAR _prevMonthNumber = CALCULATE ( MAX ( mytable[monthNumber] ), FILTER ( ALL ( myTable ), myTable[monthNumber] < _monthNumberCurrent ) ) //filter the table to all month numbers less than this month number, and get the max value which is the month before var _lastMonthFlag = CALCULATE(MAX(myTable[Flag]),FILTER(ALL(myTable),myTable[MonthNumber]=_prevMonthNumber)) RETURN DIVIDE ( _thisMonthFlag + _lastMonthFlag, IF(_lastMonthFlag = 0,1,2 ))
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πare nice too.
Nathaniel