如果当前行值与Power Bi中的先前行值匹配,如何找到当前行值?

问题描述 投票:1回答:1

如果条件与上一个行值匹配,我正在尝试查找当前行值

enter image description here

我的状况是

1)如果我的跟踪列值是T645,那么我必须检查下一个交易值是“ T644”,“ TA63”或“ T643”,但新列中的任何一个都不是BZ12。我必须采取T645列的TotalPremium值,其他视图不是

我的代码是

sub Value = CALCULATE(SUM('Table'[TotalPremium]),FILTER(ALL('Table'),
        'Table'[trac] = "T645" && EARLIER('Table'[trac])= "T644" || 
        EARLIER ('Table'[trac]) = "TA63" || EARLIER ('Table'[trac]) = "T643" && 
        EARLIER ('Table'[trac]) <> "BZ12" && 'Table'[Stat] = "PS"))

输出:

enter image description here

但预期输出是

enter image description here

powerbi powerbi-desktop powerbi-embedded powerbi-datasource powerbi-custom-visuals
1个回答
1
投票

最后,我已经解决了使用索引概念的问题,我的意思是我创建了用于比较当前值和下一个值的索引列

代码:

New Val = 
    VAR device = 'Table'[trac]    
    VAR ind = 'Table'[Index]
    VAR preInd= ind-1
    VAR TotalPremiumPreDate  = 
      SUMX(
        FILTER(
          'Table', 'Table'[Index] = preInd && ('Table'[date] >= MIN('Table'[date]) 
          && 'Table'[date] <= MAX('Table'[date]) ) &&
          'Table'[trac] = "T645" && (EARLIER('Table'[trac])= "T644" || 
                EARLIER ('Table'[trac]) = "TA63" || EARLIER ('Table'[trac]) = "T643") && 
                EARLIER ('Table'[trac]) <> "BZ12" && 'Table'[Stat] = "PS"  
        ),
        'Table'[TotalPremium]
    )
    RETURN TotalPremiumPreDate

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.