简体   繁体   English

Power BI 用户关系作为计算列加入 Not Measure

[英]power BI user relationship join as a calculated column Not Measure

I have two tables我有两张桌子

 Primary Diag
L021
L022
L023
L024
L025
L026

and Look_Up_New和 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

there are two relationship one active and the other not有两种关系,一种是活跃的,另一种不是在此处输入图片说明

The active one is ICD when I wrote the below dax for the active one it works fine当我为活动的一个写下面的 dax 时,活动的一个是ICD ,它工作正常

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

but when i wrote for the inactive one i got an error但是当我为不活跃的人写作时,我得到了一个错误

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

在此处输入图片说明

How can I correct it我该如何纠正它

The reason this fails is that CALCULATE forces a context transition (ie it transforms row context into filter context ), which means RELATED no longer has the row context it needs to operate.失败的原因是 CALCULATE 强制上下文转换(即将行上下文转换为过滤器上下文),这意味着 RELATED 不再具有它需要操作的行上下文。

Note this remark from the documentation :请注意文档中的此评论:

The RELATED function needs a row context; RELATED 函数需要一个行上下文; 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.表扫描函数(例如 SUMX)获取当前行值的值,然后扫描另一个表以查找该值的实例。

I'd suggest a slightly different approach:我建议采用稍微不同的方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM