首页 文章

年度差异计算错误“EARLIER / EARLIEST”指的是不存在的早期行上下文

提问于
浏览
0

在尝试计算年度差异时(现在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]))

虽然我对这些含义有所了解,但我不知道如何修复它们 . 这是我的 table .

enter image description here

这就是我期望的结果 .

enter image description here

我还没有得到答复 . Calculate Year over Year Variance.

实际数据样本:

enter image description here

1 回答

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

    我的最终输出

    Final Output on the Power BI Dashboard

    主要余额具有在输出表的值窗格中选择的函数SUM,其中年份不进行汇总 .

    我的最佳实践

    • 创建复杂度量时始终使用变量以简化公式 .

    • 然后仅返回Measure的一部分以检查输出是否符合预期 .

    如果它有帮助,请告诉我 .

相关问题