计算累计值

时间:2019-01-11 12:18:55

标签: powerbi dax powerbi-desktop

我正在尝试计算累积值。我尝试了以下公式,但没有一个起作用。

Cumulative_Forecast = CALCULATE(sum(TEAMS_Forecast_LineItems[ForeCast_Value]),
filter(ALLEXCEPT(TEAMS_Forecast_LineItems,TEAMS_Forecast_LineItems[ForeCast_Year]), 
TEAMS_Forecast_LineItems[MonthNumber]<=EARLIER(TEAMS_Forecast_LineItems[MonthNumber])))



Cumulative_Forecast2 = VAR RowDate = TEAMS_Forecast_LineItems[Forecast_Date]
return CALCULATE(sum(TEAMS_Forecast_LineItems[ForeCast_Value]), 
FILTER(TEAMS_Forecast_LineItems, TEAMS_Forecast_LineItems[Forecast_Date]
<=RowDate && YEAR ( TEAMS_Forecast_LineItems[Forecast_Date] ) = YEAR ( RowDate ))) 



Cumulative_Forecast3 = TOTALYTD(sum(TEAMS_Forecast_LineItems[ForeCast_Value]), 
'Calendar'[Date]) 



Cumulative_Forecast4 = CALCULATE(sum(TEAMS_Forecast_LineItems[ForeCast_Value]),
filter(ALL(DimDate[Date]), DimDate[Date] <= Max(DimDate[Date])) ) 

以下是一些记录示例:

ForeCast_Value   Month   MonthNumber     ForeCast_BU     ForeCast_Year   ForeCast_ID
71100   Sep 9   Business1   2018    10648
71100   Oct 10  Business1   2018    10648
81000   Sep 9   Business1   2018    10649
71200   Sep 9   Business2   2018    10700
80500   Sep 9   Business2   2017    10500
80600   Oct 10  Business2   2017    10500
81100   Sep 9   Business2   2018    10650

我有一个折线图;月在轴上,BU在图例上,值在值上。

所有切片器年份均已选择

Business 1= 152100 and Business 2 =232800 on September 
Business 1= 71100 and Business 2 =80600 on October   

选择切片机年份为

Business 2=80600 on Sep 
Business 2=80500 on Oct   

我想为累积值创建一个新的折线图。所需值为:
当切片器年份全部选定

Business 1= 152100 and Business 2 =232800 on September 
Business 1= 223200 and Business 2 =313400 on October   

选择slicer year = 2017时

Business 2=80600 on Sep 
Business 2=161100 on Oct  

1 个答案:

答案 0 :(得分:0)

下面的DAX公式可以帮助您获得预期的结果:

Cumilative_Forecast = 计算 (     总和(TEAMS_Forecast_LineItems [ForeCast_Value]),      FILTER(ALL(TEAMS_Forecast_LineItems),TEAMS_Forecast_LineItems [ForeCast_BU] = max(TEAMS_Forecast_LineItems [ForeCast_BU])),FILTER(ALL(TEAMS_Forecast_LineItems),TEAMS_Forecast_LineItems []     全部(TEAMS_Forecast_LineItems),     TEAMS_Forecast_LineItems [ForeCast_Year] <= max(TEAMS_Forecast_LineItems [ForeCast_Year]))

上面的公式给出了结果 “当切片器年份全部选定时

9月份的业务1 = 152100,业务2 = 232800 10月的业务1 = 71100,业务2 = 80600“

Cumulative_Value = 计算 (     总和(TEAMS_Forecast_LineItems [ForeCast_Value]),      FILTER(ALL(TEAMS_Forecast_LineItems),TEAMS_Forecast_LineItems [ForeCast_BU] = max(TEAMS_Forecast_LineItems [ForeCast_BU])),FILTER(     全部(TEAMS_Forecast_LineItems),     TEAMS_Forecast_LineItems [MonthNumber] <=最大值(TEAMS_Forecast_LineItems [MonthNumber]))

上面的公式给出了结果 “我想为累积值创建一个新的折线图。所需的值为: 当切片器年份全部选定时

9月份的业务1 = 152100,业务2 = 232800 10月份的业务1 = 223200和业务2 = 313400”

请告诉我这是否达到了您的预期结果。