历年平均每月滚动/移动 [英] Rolling/Moving average by month over years

查看:142
本文介绍了历年平均每月滚动/移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望获得3年中特定月份的移动平均值和总和,而不是每月滚动平均值。我想看看多年来这些月业务的发展趋势,并希望将平均值作为基准。

Looking to get a moving average and aggregate sum over years by specific months over 3 years, not monthly rolling average. I want to see how our business trends by month over the years and want to have the average as a baseline.

即:


  • 2011年1月,2012年1月,2013年1月等

  • January 2011, January 2012, January 2013, etc

2011年2月,2012年2月,2月2013等

February 2011, February 2012, February 2013, etc


到目前为止,我所能做的就是得到3所选年份的SUM,甚至关闭。

So far all I have been able to do is get a 3 year SUM from selected year, and even that is off.

例如:选定的月份= 2013年1月,总计包括从2011年2月到> 2013年1月的所有月份。相反,这些年份中我只需要1月。

Ex: selected month = Jan 2013, aggregate includes all months from February 2011 -->Jan 2013. Instead I need just January for those years.

尝试了日期测量:

CALCULATE([total],
DATESINPERIOD(Time [Pk_Date],
LASTDATE(Time [PK_Date]),-3,Year

目标是从所选年份开始倒退3年

Goal is to roll back 3-years from selected year


  • 一月


    • 2011:50

    • 2012:55

    • 2013:53

    • 2014:57

    • 2015:47

    • January
      • 2011: 50
      • 2012: 55
      • 2013: 53
      • 2014: 57
      • 2015: 47

      在这种情况下,滚动平均和运行总计应为:

      In this scenario rolling avg and running totals should be:

      2014年平均= 55 |总和= 165

      2015年平均= 52 | sum = 157

      2014 avg = 55 | sum = 165

      2015 avg = 52 | sum = 157


      感谢您的帮助!

      any help is appreciated!

      推荐答案

      您超级亲密,您只是错过了额外的过滤器,无法将您选择的日期时段过滤到所选的月份号。

      You're super close, you just missed the extra filter to filter that date period you selected down to the selected month number.

      首先,请确保您的日期表中有一列用于月份的数字。假设它称为 MonthNumber

      First, make sure there's a column for the month number in your date table. Let's assume it's called MonthNumber.

      下一步,创建一个度量以捕获您选择的月份。

      Next, create a measure to capture your selected month.

      ChosenMonth :=
      MAX ( Time[MonthNumber] )
      

      由于数据透视表中的每一行将有一个月,这将只返回该月作为度量,因此您可以在以后的计算中使用它。您也可以使用 SUM() MIN()等,因为只有一个值。

      Since each row in your pivot table will have one month, this will just return that month as a measure so you can use it in later calculations. You could also use SUM(), MIN(), etc. since there's only one value.

      RollingAverage :=
      CALCULATE (
          [Total],
          DATESINPERIOD (
              Time[PK_Date],
              LASTDATE ( Time[PK_Date] ),
              -3,
              YEAR
          ),
          FILTER (
              VALUES ( Time[MonthNumber] ),
              Time[MonthNumber] = [ChosenMonth]
          )
      )
      

      这就是为什么为诸如所选月份之类的事物创建中间的,隐藏的度量很重要的原因,因此您可以在DAX确实没有等效住宿的日期上重新申请该上下文。

      This is why it's important to create intermediate, hidden measures for things like the chosen month, so you can reapply that context on a set of dates where DAX really has no equivalent accommodation.

      这篇关于历年平均每月滚动/移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆