简体   繁体   中英

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

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

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.

Note this remark from the 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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