Forum Discussion

NMahi1703's avatar
NMahi1703
Frequent Visitor
3 years ago
Solved

Advanced multiple tables join's with conditions

Hi Team,  I have two tables as below, Need to filter the data based on few conditions as listed. Table1: ID Account ID 1811 3630 3291 7625 5567 7625 5567 3631 3201 3631 ...
  • PaulDBrown's avatar
    PaulDBrown
    3 years ago

    See if this works for you.

    FIrst I created dimension tables using:

    Then create the following measures:

     

    Common Bill ID =
    VAR _Int =
        COUNTROWS (
            INTERSECT ( VALUES ( 'Table 2'[BilliD] ), VALUES ( 'Table 1'[ID] ) )
        )
    RETURN
        IF ( _Int = 1, 1 )
    

     

    To use as a filter in the filter pane, use this measure and set the value to = 1:

     

    Row Filter =
    VAR _AccIDs =
        COUNTROWS (
            INTERSECT (
                VALUES ( 'Account Table'[Account ID] ),
                CALCULATETABLE (
                    VALUES ( 'Table 2'[Account Number] ),
                    FILTER (
                        ALLEXCEPT ( 'Table 2', 'Table 2'[Account Number] ),
                        [Common Bill ID] = 1
                    )
                )
            )
        )
    RETURN
        SWITCH ( TRUE (), [Common Bill ID] = 1, 1, ISBLANK ( _AccIDs ), 1, 0 )
    

     

    To obtain the highest Status by account and filtered rows, use:

     

    Status =
    VAR _ID =
        MAX ( 'Account Table'[Account ID] )
    VAR _ImpValues =
        CALCULATETABLE (
            VALUES ( 'Status Table'[Imp] ),
            FILTER ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Account Number] = _ID )
        )
    VAR _MaxImp =
        MAXX ( _ImpValues, 'Status Table'[Imp] )
    VAR _Status =
        LOOKUPVALUE ( 'Status Table'[Acc Status], 'Status Table'[Imp], _MaxImp )
    RETURN
        IF ( ISBLANK ( MAX ( 'Table 2'[Version] ) ), BLANK (), _Status )
    
    

     

    and you will get:

     Sample PBIX file attached