Forum Discussion

Elzzie's avatar
Elzzie
Frequent Visitor
2 years ago
Solved

Check column from another table if it contains two values, and return a different string as result

Hi community,

I'm quite new to powerbi, and have a specific usecase I cannot figure out. I hope you can help me out here. 

I have the following two tables:

Event

EventIDEventName
1Birthday
2Wedding
3Party


Guest

GuestEventIDGuestLocation
11Outside
21Outside
32Inside
42Inside
53Inside
63Outside


The two tables are related through EventID. What I want as a result is to have an extra column in table "Event", which checks the location of the guests that are present at a specific EventID. Since for EventID 3, there are 2 different locations, I want to return that as "Both". I'm searching for the following result: 

EventIDEventNameGuestLocation
1BirthdayOutside
2WeddingInside
3PartyBoth


In my current situation I have two possible locations, but in the future this might be 3 or 4. So if that could be taken into account, that would be really nice. If that is really difficult I'm happy with a solution for two locations. 

I'm looking for a solution in DAX.

  • Elzzie PBIX is attached below signature.

    GuestLocation = 
        VAR __Table = SUMMARIZE( RELATEDTABLE(Guest), [GuestLocation] )
        VAR __Rows = COUNTROWS( __Table )
        VAR __Result = 
            IF( 
                __Rows = 1,
                MAXX( __Table, [GuestLocation] ),
                "Multiple (" & __Rows & ")"
            )
    RETURN
        __Result

2 Replies

  • Elzzie's avatar
    Elzzie
    Frequent Visitor

    Greg_Deckler,
    Thank you so much for this, my projectmanager will be very happy on Monday. 

    It is not giving back the strings I would like, but I fixed that with another column matching the different options to the corresponding string I need. 

    Enjoy your weekend!

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Elzzie PBIX is attached below signature.

    GuestLocation = 
        VAR __Table = SUMMARIZE( RELATEDTABLE(Guest), [GuestLocation] )
        VAR __Rows = COUNTROWS( __Table )
        VAR __Result = 
            IF( 
                __Rows = 1,
                MAXX( __Table, [GuestLocation] ),
                "Multiple (" & __Rows & ")"
            )
    RETURN
        __Result