DAX:如何根据动态时间段计算?

时间:2016-11-03 19:47:43

标签: time count powerbi dax period

我有一个数据集,如下面的示例1图像中所示,我需要生成每个序列号的事件比率(如图所示的汇总表)。

我在这里得到的曲线球是事件的数量和子事件的数量是每月,序列号的数量是每3个月,因此SN计数需要动态地移动时间段。换句话说,在3月我需要将3月份的事件从1月到3月除以SN的数量,而在4月份,我需要将4月份的事件除以2月份的SN计数。四月。

有关如何做到这一点的任何想法?

提前致谢所有帮助

Sample 1

1 个答案:

答案 0 :(得分:0)

您必须在表格中创建两个计算列以获取月份数,并且应计算来自非重复计数的月份。

MonthNumber =
SWITCH(
[Event Month],"Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,
"Jul",7,"Ago",8,"Sep",9,"Oct",10,"Nov",11,"Dec",12)

MonthFrom =
SWITCH([Event Month],"Jan",1,"Feb",1,"Mar",1,"Apr",2,"May",3,"Jun",4,"Jul",5,"Ago",6,
"Sep",7,"Oct",8,"Nov",9,"Dec",10)

然后你可以创建这个措施,给出SN过去三个月的不同数量:

SN Count =
CALCULATE (
    DISTINCTCOUNT ( Event[SN] ),
    FILTER (
        ALL ( Event ),
        Event[MonthNumber] >= MAX ( [MonthFrom] )
            && [MonthNumber] <= MAX ( [MonthNumber] )
    )
)

如果有帮助,请告诉我。