且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

power bi dax 的滚动月平均值

更新时间:2023-09-23 13:44:46

我见过 Rob Collie 处理除以 12,而不是除以

Instead of dividing by 12, I have seen Rob Collie handle the division by

COUNTROWS ( VALUES ( 'Date'[Year-Month] ) )

COUNTROWS ( VALUES ( 'Date'[Year-Month] ) )

其中 [Year-Month] 是日期"表中的计算列:

where [Year-Month] is a calculated column in the 'Date' table:

= FORMAT ('日期'[日期], "YYYY-mm" )

= FORMAT ( 'Date'[Date], "YYYY-mm" )

以这种方式使用 VALUES 还可以处理可用数据少于 12 个月的情况.

Using VALUES in this way also handles cases where the available data covers less than 12 months.

我还看到 Chandoo 使用了类似的方法,但使用 COUNTROWS 检查是否有十二个月可用于作为滚动平均值的基础(如果没有,则返回空白).

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).

推荐文章