简体   繁体   English

Power BI(DAX或Power Query)中3个月滚动平均值的季度总和

[英]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. 我有每月的结果,需要显示为3个月的滚动平均值,有时需要按月显示,有时需要作为季度/年的3个月滚动平均值的总和。

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)) 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)) / CALCULATE(DISTINCTCOUNT(Calendar_Lookup [date]),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? 在Power Query或DAX中创建一个列,该列包含3个月的平均值,这样我就可以根据需要对其求和? 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 在这种情况下,听起来像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]. 此度量将首先使用VALUES函数生成每个[Year_Month]的不同列表。 It would then calculate using your existing [3-Mo Rolling Avg] for each [Year_Month] and then sum the results. 然后,它将使用您现有的[3-Mo Rolling Avg]为每个[Year_Month]进行计算,然后对结果求和。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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