Forum Discussion

tom1tas's avatar
tom1tas
Frequent Visitor
3 years ago

Obtaining moving average from a measure

Hello everyone, in the table included below I have 2 measures that show me headcount and leaves. Now I need to  turn these  measures into  a moving average for the headcount which is calculated  from the  months previous to the date selected in the date slicer.

  • Additionally I need to get a measure that sums  the leaves from the previous months to the date selected on the slicer from each matching company as shown in the table below. 
 

                   

New Expected table (Date Slicer January 2023):

CompanyHeadcount     Leaves Cummulative Leaves (From previous month)Moving Average Headcount (From previous month to filtered date)
Food101 null  null or 0
Sports201 null  null or 0
Cars301 null  null or 0

New Expected table Filtered (February 2023):

CompanyHeadcountLeavesCummulative Leaves (From previous month)Moving Average Headcount (compared to previous month same company hc)
Food111215.5
Sports211220.5
Cars311230.5

 

The Measures in the model are the following:
Current HC = CALCULATE(SUM('Forecast Query'[Forecast Value]),'Forecast Query'[Forecast Date]==MAX('Forecast Query'[Forecast Date])) 

Leaves:  L leaves are calculated with the 

Total Leaves = DISTINCTCOUNT('Media Leaves'[Career Settings ID])
 
Notice I had achieved this on another format as shown on the post : https://community.powerbi.com/t5/Desktop/Get-Moving-Average-from-an-existing-measure/m-p/3080565#M1045389 but when I changed the table columns the moving average measure created as a solution for previous post, stopped working

 

 

 

 

 

Moving Average Headcount Previous post solution =
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), 'Table'[Date] <= cur_date )
RETURN
    AVERAGEX ( tmp, [Head count] )

 

 

 

 

 

1 Reply