当尝试计算逐年差异(现在2天未成功)时,我收到以下错误消息。
EARLIER / EARLIEST是指不存在的较早行上下文。
YOY Variance = var PreviousYearPrinBal = CALCULATE(SUM(Deals[Principal Balance]),FILTER(ALL(Deals[Close Date].[Year]),Deals[Close Date].[Year] = EARLIER(Deals[Close Date].[Year])))
return
if(PreviousYearPrinBal = BLANK(), BLANK(), Deals[PrincipalBalance] - PreviousYearPrinBal)
在另一个SO问题中,有一个不同的方法给了我以下错误:
在对函数“ SAMEPERIODLASTYEAR”的调用中指定的列不是DATE类型。不支持。
yoy = CALCULATE([PrincipalBalance], SAMEPERIODLASTYEAR(Deals[Close Date].[Year]))
虽然我对这些含义有所了解,但对如何解决它们却一无所知。这是我的桌子。
这就是我期望的结果。
我尝试在Power BI社区中发布此问题,但尚未收到答案。 Calculate Year over Year Variance.
实际数据示例:
答案 0 :(得分:1)
1)创建的年份和年份差异列(计算列)
Year = YEAR(Table1[Date])
Year Difference = Table1[Year] - Min(Table1[Year])
2)创建方差(度量)
Variance =
Var current_YearDifference = SELECTEDVALUE(Table1[Year Difference])
Var Current_PrincipalBalance = CALCULATE(SUM(Table1[Principal Balance]),FILTER(ALL(Table1), Table1[Year Difference] = (current_YearDifference)))
Var Previous_PrincipalBalance = CALCULATE(SUM(Table1[Principal Balance]),FILTER(ALL(Table1), Table1[Year Difference] = (current_YearDifference - 1)))
Return if(current_YearDifference <> 0, (Current_PrincipalBalance - Previous_PrincipalBalance), 0)
3)最后创建了百分比(度量)方差,
Variance in terms of Percentage =
Var current_YearDifference = SELECTEDVALUE(Table1[Year Difference])
Var Current_PrincipalBalance = CALCULATE(SUM(Table1[Principal Balance]),FILTER(ALL(Table1), Table1[Year Difference] = (current_YearDifference)))
Var Previous_PrincipalBalance = CALCULATE(SUM(Table1[Principal Balance]),FILTER(ALL(Table1), Table1[Year Difference] = (current_YearDifference - 1)))
Return if(current_YearDifference <> 0, ((Current_PrincipalBalance - Previous_PrincipalBalance) / Previous_PrincipalBalance), 0)
“本金”具有在“输出表”的“值”窗格中选择的SUM函数,因为“年”是“不汇总”。
请告诉我,是否有帮助。