使用 DAX 在 PowerBI 中计算前一个月的 SalesAmount 总和

calculate sum of SalesAmount of prevouis month in PowerBI using DAX

我花了几个小时尝试在 PowerBI 中计算预览月的 SalesAmount,但没有成功。我不知道我做错了什么!! 这是我的 table:

这是我的 DAX 函数

PreviousMonth = CALCULATE(SUM(FactInternetSalesTEST[SalesAmount]), 
  DATEADD(FactInternetSalesTEST[SalesDate],-1,MONTH)

结果如下:

为什么该列是空的?

用这个添加索引列:

Index = COUNTROWS(Filter(FactInternetSalesTEST, FactInternetSalesTEST[SalesDate]<=EARLIER(FactInternetSalesTEST[SalesDate])))

然后使用索引通过添加另一列来定位较早的日期值:

PreviousMonth = CALCULATE(SUMX(FactInternetSalesTEST,FactInternetSalesTEST[SalesAmount]),FILTER(FactInternetSalesTEST,FactInternetSalesTEST[Index]=EARLIER(FactInternetSalesTEST[Index])-1))

你会得到这个: