Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Fetch the values from another table by matching column x with eith column A or B in the other table

Hello 

I need the values from table 1 by matching column x in table 1 with either column a or column b in table 2.
I tried to establish two relationships with table 1 to table 2 but I can only make one relationship active 

I have a column in table 1 that either matches column a in table 2 or column b in table 2.
Is there any better way to bring in all the values matching column a or column b

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

That would be someting like this.

Values = 
CALCULATE (
    SUM ( 'Table 2'[Values] ),
    FILTER (
        ALL ( 'Table 2'[ENPNSC_] ),
        'Table 2'[ENPNSC_] = 'Table 1'[Enpnsc_Calculated]
    )
) + 
CALCULATE (
    SUM ( 'Table 2'[Values] ),
    FILTER (
        ALL ( 'Table 2'[ENPNSC_] ),
        'Table 2'[ENPNSC_] = 'Table 1'[Pcsc_calcualted]
    )
)

jdbuchanan71_0-1659013973554.png

 

 

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

That would be someting like this.

Values = 
CALCULATE (
    SUM ( 'Table 2'[Values] ),
    FILTER (
        ALL ( 'Table 2'[ENPNSC_] ),
        'Table 2'[ENPNSC_] = 'Table 1'[Enpnsc_Calculated]
    )
) + 
CALCULATE (
    SUM ( 'Table 2'[Values] ),
    FILTER (
        ALL ( 'Table 2'[ENPNSC_] ),
        'Table 2'[ENPNSC_] = 'Table 1'[Pcsc_calcualted]
    )
)

jdbuchanan71_0-1659013973554.png

 

 

Thank you @jdbuchanan71 ,
It worked, I really appreciate it 😊

jdbuchanan71
Super User
Super User

Try it like this instead.

Value =
VAR _search = 'Table 1'[column x]
RETURN
    COALESCE (
        CALCULATE (
            FIRSTNONBLANK ( 'Table 2'[value], 1 ),
            FILTER ( ALL ( 'Table 2'[column a] ), 'Table 2'[column a] = _search )
        ),
        CALCULATE (
            FIRSTNONBLANK ( 'Table 2'[value], 1 ),
            FILTER ( ALL ( 'Table 2'[column b] ), 'Table 2'[column b] = _search )
        )
    )

jdbuchanan71_0-1658953286043.png

 

Hello @jdbuchanan71 

I'm sorry to revert again,
That is just picking first value in the column, i would like to pick every value 
For instance : 

bhavana097_0-1658999231903.png

Table 1 should be able to pick all the values in table 2 via matching either enpnsc_calculated field & ecpc_calculated field with table 2 [ ENPNSC_ ] field


Thank you very much in advance 

bhavana097
Frequent Visitor

Hello @jdbuchanan71 

Thank you for the solution, But i got an error back saying "mutliple values was supplied where single values are being expected".

bhavana097_0-1658947282678.png


Im sorry, i Forgot to mention that for one value in column a (enpnsc) & column b(pcsc) from table1 has the mutiple value in column x( enpnsc) table 2 
Targeted value is agency cost 

bhavana097_1-1658947814825.png

Im looking forward to discussing with you  



jdbuchanan71
Super User
Super User

@Anonymous 

You can add a column to table 1 like this.

 

Value = 
COALESCE(
    LOOKUPVALUE('table 2'[value],'table 2'[column a],'table 1'[column x]),
    LOOKUPVALUE('table 2'[value],'table 2'[column b],'table 1'[column x])
)

jdbuchanan71_1-1658937255611.png

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.