power BI 用户关系连接作为计算列 Not Measure

power BI user relationship join as a calculated column Not Measure

我有两张桌子

 Primary Diag
L021
L022
L023
L024
L025
L026

和Look_Up_New

ICD ICD2    Inclusion Type
L021    L021    3
L022    L022    2
L023    L023    2
L024    L024    4
L025    L025    5
L026    L026    4
L027    L029    5

有两种关系,一种是活跃的,另一种不是

活跃的是ICD 当我为活动的写下面的 dax 时它工作正常

Diag 1 = IF(diag[Primary Diag]=BLANK(),"X",
            IF(RELATED(Look_Up_New[ICD]) = BLANK(),"X",
              RELATED(Look_Up_New[Inclusion Type])))

但是当我为不活跃的那个写的时候我得到了一个错误

Diag 2 = CALCULATE(IF(diag[Sec. Diag 2]=BLANK(),"X",
            IF(RELATED(Look_Up_New[ICD2]) = BLANK(),"X",
              RELATED(Look_Up_New[Inclusion Type]))),
              USERELATIONSHIP(Look_Up_New[ICD2],Diag[Primary Diag]))

我该如何更正它

失败的原因是 CALCULATE 强制执行 context transition (i.e. it transforms row context into filter context),这意味着 RELATED 不再具有它需要操作的行上下文。

请注意 documentation 的评论:

The RELATED function needs a row context; therefore, it can only be used in calculated column expression, where the current row context is unambiguous, or as a nested function in an expression that uses a table scanning function. A table scanning function, such as SUMX, gets the value of the current row value and then scans another table for instances of that value.

我建议采用稍微不同的方法:

Diag 1 = 
CALCULATE ( SELECTEDVALUE ( Look_Up_New[Inclusion Type], "X" ) )

Diag 2 = 
CALCULATE (
    SELECTEDVALUE ( Look_Up_New[Inclusion Type], "X" ),
    USERELATIONSHIP ( Diag[Primary Diag], Look_Up_New[ICD2] )
)