Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

rolling average last 30 days

Dear All 

 

I have been trying to calculate the rolling average 30 days for every day. I have used below query which is working for all excep the minimum date in the data base 

For ex: we have may month data then below query work fine for all days except 1st may on 1st may the value should be zero but it is showing average of same day(1stmay) for rest other days it is working fine. can you please support 

 

 

 

Averageoflast30days =
VAR tday= LASTDATE('KPI TABLE'[DATE])
VAR tday_2 = tday-1
return
IF(ISBLANK(CALCULATE(AVERAGE('KPI TABLE'[COMPLETED_ORD_COUNT]),ALLEXCEPT('KPI TABLE','KPI TABLE'[BUSINESS_SERVICE],'KPI TABLE'[DIMENSION],'KPI TABLE'[DATE]),DATESINPERIOD('KPI TABLE'[DATE],tday_2,-31,DAY))),0,CALCULATE(AVERAGE('KPI TABLE'[COMPLETED_ORD_COUNT]),ALLEXCEPT('KPI TABLE','KPI TABLE'[BUSINESS_SERVICE],'KPI TABLE'[DIMENSION],'KPI TABLE'[DATE]),DATESINPERIOD('KPI TABLE'[DATE],tday_2,-31,DAY)))

3 Replies