简体   繁体   中英

Quarterly sum of 3 month rolling average in Power BI (DAX or Power Query)

I have monthly results that I need to present as a 3 month rolling average, sometimes at a monthly level and sometimes as a sum of the 3 month rollling average for the quarter/year.

At the monthly level I've found the below formula to work well:

3-Mo Rolling Avg = CALCULATE([Market Performance], DATESINPERIOD(Calendar_Lookup[date], MAX(Calendar_Lookup[date]), -3, MONTH))

/ CALCULATE(DISTINCTCOUNT(Calendar_Lookup[Year_Month]), DATESINPERIOD(Calendar_Lookup[date], LASTDATE(Calendar_Lookup[date]), -3, MONTH))

But, when I show quarterly or annual results it shows one 3 month average instead of a sum of the 3 month averages for the period. How would you solve this?

The options I can see are:

  1. Create a column in either Power Query or DAX that holds the 3 month averages so then I can SUM them as needed? Any advice on how to do this?

  2. Figure out how to do a SUM of a measure. Any advice on how to do this?

  3. Build a series of measures at the monthly, quarterly and annual level. Not a great solution as it doesn't allow me to work fast when performing analysis because I have to be careful of pulling the right measure.

Any advice would be appreciated! Thanks!

But, when I show quarterly or annual results it shows one 3 month average instead of a sum of the 3 month averages for the period. How would you solve this?

Based on this part, it sounds like you need one of the iterator functions. In this case it sounds like a SUMX

The basic layout would be something along the lines of

Measure:= SUMX( VALUES(Calendar_Lookup[Year_Month] ) ,  [3-Mo Rolling Avg] )

This measure would first using VALUES function generate a distinct list of each [Year_Month]. It would then calculate using your existing [3-Mo Rolling Avg] for each [Year_Month] and then sum the results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM