简体   繁体   English

滚动月平均功率bi dax

[英]Rolling month average in power bi dax

I have these two columns: SALES_CALLSID QFQ4TA5006C2 QZPIOA18LW8A QS4GSA300PU0 ....; 我有这两列:SALES_CALLSID QFQ4TA5006C2 QZPIOA18LW8A QS4GSA300PU0 ....; and MEETING_DATE 7/10/2014 12:00 3/27/2015 12:00 11/3/2015 12:00 和MEETING_DATE 7/10/2014 12:00 3/27/2015 12:00 11/3/2015 12:00

I need the count of the first column (salesid) but this count should be a trailing twelve month average for every month, ie for example for July- the count of sales id of july + count of last 11 months (ie based on the meeting date column), similarly this measure has to be made for every other month. 我需要第一列(salesid)的计数,但这个计数应该是每个月的平均12个月平均值,例如7月 - 7月的销售额+最近11个月的计数(即基于会议)日期栏),类似地,这个措施必须每隔一个月进行一次。

The "Sales Call ID" column is a text field. “销售呼叫ID”列是文本字段。 I can see the count using the formula COUNTA(AccountSalesCalls[SALES_CALLSID])`. 我可以使用公式COUNTA(AccountSalesCalls [SALES_CALLSID])来查看计数。

The formula i built to get the total count of sales id for last 12 months is as follows: 我为获得过去12个月的销售ID总数而构建的公式如下:

CALCULATE (
    COUNTA ( AccountSalesCalls[SALES_CALLSID] ),
    DATESBETWEEN (
        AccountSalesCalls[MEETING_DATE],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( AccountSalesCalls[MEETING_DATE] ) ) ),
        LASTDATE ( AccountSalesCalls[MEETING_DATE] )
    )
)

When i do this i get an error: 当我这样做时,我得到一个错误:

A date column containing duplicate dates was specified in the call to function 'DATESBETWEEN'. 在函数“DATESBETWEEN”的调用中指定了包含重复日期的日期列。 This is not supported. 这不受支持。

I then built a DATE table and replaced MEETING_DATE column with column in DATE table as follows: 然后,我构建了一个DATE表,并将DET表中的列替换为MEETING_DATE列,如下所示:

CALCULATE (
    COUNTA ( AccountSalesCalls[SALES_CALLSID] ),
    DATESBETWEEN (
        'Date'[Date],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( AccountSalesCalls[MEETING_DATE] ) ) ),
        LASTDATE ( AccountSalesCalls[MEETING_DATE] )
    )
)

This just gives me the count of that month which is the same result as COUNTA(AccountSalesCalls[SALES_CALLSID]) . 这只是给了我那个月的计数,这与COUNTA(AccountSalesCalls[SALES_CALLSID])结果相同。

I still haven't done the division part to get the average but first wanted to figure out how to make the total count work. 我仍然没有完成分区以获得平均值,但首先想要弄清楚如何使总计数工作。 Any help would be appreciated. 任何帮助,将不胜感激。

You were nearly there. 你快到了。

The calculated column: 计算列:

Average = CALCULATE (
  COUNTA ( AccountSalesCalls[SALES_CALLSID] ) / 12,
  DATESBETWEEN(
    AccountSalesCalls[MEETING_DATE],
    DATEADD(AccountSalesCalls[MEETING_DATE], -12, MONTH),
    AccountSalesCalls[MEETING_DATE]
  ),
  ALL(AccountSalesCalls)
)

Note this divides by a constant (12), which would be incorrect for the first year of your data. 请注意,这除以常量(12),这对于数据的第一年是不正确的。 You will have to decide how to deal with this (if at all). 你必须决定如何处理这个问题(如果有的话)。

One option could be to divide by the date range of existing selected data instead: 一种选择可以是除以现有选定数据的日期范围:

Average = CALCULATE (
  COUNTA ( AccountSalesCalls[SALES_CALLSID] ) / 
    DATEDIFF( MIN(AccountSalesCalls[MEETING_DATE] ),
      MAX( AccountSalesCalls[MEETING_DATE] ),MONTH),
  DATESBETWEEN(...

More or moving averages using DAX 使用DAX的更多或移动平均线

Instead of dividing by 12, I have seen Rob Collie handle the division by 我没有除以12,而是看到Rob Collie处理分裂

COUNTROWS ( VALUES ( 'Date'[Year-Month] ) ) COUNTROWS(价值观('日期'[年 - 月]))

where [Year-Month] is a calculated column in the 'Date' table: 其中[Year-Month]是'Date'表中的计算列:

= FORMAT ( 'Date'[Date], "YYYY-mm" ) =格式('日期'[日期],“YYYY-mm”)

Using VALUES in this way also handles cases where the available data covers less than 12 months. 以这种方式使用VALUES还可以处理可用数据覆盖不到12个月的情况。

I have also seen Chandoo use a similar approach, but using the COUNTROWS to check if there are twelve months available to base the rolling average on (and if not, return blank). 我也看到Chandoo使用类似的方法,但是使用COUNTROWS检查是否有12个月可用于基于滚动平均值(如果不是,则返回空白)。

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

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