我试图计算PowerBI中每月的净收入变化百分比。
遵循Time Patterns"期间比较模式",其中说明:
例如,月度计算(MOM)将当前选择与一个月前的相同选择进行比较。
和This Reddit Post,其中说明:
扩展:CALCULATE(SUM(YourValueCol),PREVIOUSMONTH(YourDateCol))
我觉得我跟着这些。见下文:
所选模型尺寸:
Month
(一年中的月份数字)SUM(Orders[Unit Net Revenue USD])
)给出:
Month | NR
----------------------
1 $5
2 $6
3 $7
上个月的选定模型尺寸:
Previous Month
(一年中的月份数字)SUM(Orders[Unit Net Revenue USD])
)给出:
Previous Month | NR
----------------------
1 $6
2 $7
3 $8
---------------------
Total: $21
因此,我尝试将当前月NR与上个月NR进行比较,最终获得%变化:
This Month NR = CALCULATE(SUM(Orders[Unit Net Revenue USD]), 'Date - Period'[Month]) // Month = 2 (February)
Prior Month NR = CALCULATE(SUM(Orders[Unit Net Revenue USD]), 'Date - Period'[PreviousMonth]) // Month = 1 (January)
% Change = DIVIDE([This Month NR], [Prior Month NR], BLANK())-1
// Also tried:
% Change = (([This Month NR] - [Prior Month NR])/ [Prior Month NR])
对于This Month NR
,它会向我提供每行NR的总和,而对于Prior Month NR
,它会给我预期的值。为什么每月给出每年的总金额?如,
Year | Month | This Month NR | Prev Month NR
------------------------------------------------------------------
2015 1 $18 ($5 + $6 + $7 for 2015) $6
2015 2 $18 $7
2015 3 $18 $8
------------------------------------------------------------------
预期:
Year | Month | This Month NR | Prev Month NR
------------------------------------------------------------------
2015 1 $5 $4
2015 2 $6 $5
2015 3 $7 $6
------------------------------------------------------------------
如果我执行以下计算字段
NR Measure = SUM('Retailer Sales'[Net Revenue])
This Month NR = CALCULATE([NR Measure], 'Date'[Month Num])
Prior Month NR = CALCULATE([NR Measure], 'Date'[Previous Month])
然后按dimension Year
&过滤dimension Month Num
& This Month NR
& Prior Month NR
我明白了:
Year | Month | This Month NR | Prev Month NR
------------------------------------------------------------------
2015 1 $6 $6
2015 2 $7 $7
2015 3 $8 $8
------------------------------------------------------------------
预期(再次):
Year | Month | This Month NR | Prev Month NR
------------------------------------------------------------------
2015 1 $6 $5
2015 2 $7 $6
2015 3 $8 $7
------------------------------------------------------------------
上个月,如果我尝试Prior Month NR = CALCULATE([NR Measure], PREVIOUSMONTH('Retailer Sales'[Date]))
- Prior Month NR
对于相同的过滤器而言只是空白。
我在DAX中做错了什么?