Forum Discussion

allora's avatar
allora
Frequent Visitor
3 years ago
Solved

Creating conditional relationships in power bi

I have 2 tables that I would like to create a relationship between.

 

I have Column A in both table 1 and table 2 and would like to create a relationship on this column. However, in Table 2, Column A is often null. If it is null, I would like to create a relationship between Column B in table 1 and Column B in table 2. Is this possible in power bi? The goal is the get Column A, Column B, Value and NurseName in one table.

 

I have created an example below.

 

Table 1: 

Column AColumn BValue
001AA1109
002BB1123
003CC1

983

004DD1

821

 

Table 2:

Column AColumn BNurseName
001nullAlex
nullBB1Ally
003nullJohn
nullDD1Tanya
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi allora ,

     

    Please create a new calculated column.

    NurseName = 
    IF (
        COUNTROWS ( RELATEDTABLE ( 'Table 2' ) ),
        CALCULATE ( MAX ( 'Table 2'[NurseName] ), RELATEDTABLE ( 'Table 2' ) ),
        CALCULATE (
            MAX ( 'Table 2'[NurseName] ),
            USERELATIONSHIP ( 'Table 1'[Column B], 'Table 2'[Column B] )
        )
    )

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi allora ,

     

    Please create a new calculated column.

    NurseName = 
    IF (
        COUNTROWS ( RELATEDTABLE ( 'Table 2' ) ),
        CALCULATE ( MAX ( 'Table 2'[NurseName] ), RELATEDTABLE ( 'Table 2' ) ),
        CALCULATE (
            MAX ( 'Table 2'[NurseName] ),
            USERELATIONSHIP ( 'Table 1'[Column B], 'Table 2'[Column B] )
        )
    )

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum