Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Filter by two columns

Hi,
I have a table with reservations like this:

ReservationIDAreaDatePerson
11st floor01.11.2020A
2kitchen02.11.2020A
3kitchen03.11.2020C
4garden01.11.2020D
5garden02.11.2020E
6kitchen02.11.2020F
71st floor01.11.2020G

 

I'd like to have a measure that gives me all contacts of a selected person. Contacts are based on sameDate AND sameArea.
The result should look like this ("All contacts of Person A"):

PersonPrimaryContacts
AF, G

 

F and G because they we're at the same area at the same date.

 

Do you have any ideas to solve this? Please help me!
Thank you

  • Anonymous ,

     

    Try this measure:

    _Contact = 
    VAR _person = SELECTEDVALUE('Table'[Person])
    VAR _tblAreaDate = SELECTCOLUMNS(ADDCOLUMNS(SUMMARIZE(FILTER(ALL('Table'), 'Table'[Person] = _person), 'Table'[Area], 'Table'[Date]), "Combine", COMBINEVALUES(",", 'Table'[Area], 'Table'[Date])), "Combine", [Combine])
    VAR _tblMatch = CALCULATETABLE(
                    VALUES('Table'[Person]), FILTER(ALL('Table'), COMBINEVALUES(",", 'Table'[Area], 'Table'[Date]) in _tblAreaDate && 'Table'[Person] <> _person))
    
    
    RETURN CONCATENATEX(_tblMatch, 'Table'[Person], ",")
  • Hi Anonymous 

    1. Place [Person] in a table visual

    2. Create this measure and place it in the visual

     

    Primary contacts = 
    VAR datesAreas_ = SUMMARIZE ( Table1, Table1[Area], Table1[Date] )
    VAR currentPerson_ = SELECTEDVALUE ( Table1[Person] )
    VAR contacts_ =
        CALCULATETABLE (
            DISTINCT ( Table1[Person] ),
            datesAreas_,
            Table1[Person] <> currentPerson_
        )
    RETURN
        CONCATENATEX ( contacts_, [Person], ", " )

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

3 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    You can use this measure expression in a table visual with your Person column to get the shown result.  Replace Reservations with your actual table name.  Note this has two CONCATENATEX functions.  A virtual table is made for all the combinations of place and date for that person.  The first concat combines all the people that overlapped in each place time with commas.  The second concat combines those individual list into a full list separate by semi colons.

     

     

    SamePlaceDate =
    VAR thisperson =
        MIN ( Reservations[Person] )
    VAR summary =
        ADDCOLUMNS (
            SUMMARIZE (
                Reservations,
                Reservations[Area],
                Reservations[Date]
            ),
            "overlap",
                CONCATENATEX (
                    CALCULATETABLE (
                        DISTINCT ( Reservations[Person] ),
                        Reservations[Person] <> thisperson
                    ),
                    Reservations[Person],
                    ", "
                )
        )
    RETURN
        CONCATENATEX (
            summary,
            [overlap],
            "; "
        )

     

    Regards,

    Pat

  • AlB's avatar
    AlB
    Community Champion

    Hi Anonymous 

    1. Place [Person] in a table visual

    2. Create this measure and place it in the visual

     

    Primary contacts = 
    VAR datesAreas_ = SUMMARIZE ( Table1, Table1[Area], Table1[Date] )
    VAR currentPerson_ = SELECTEDVALUE ( Table1[Person] )
    VAR contacts_ =
        CALCULATETABLE (
            DISTINCT ( Table1[Person] ),
            datesAreas_,
            Table1[Person] <> currentPerson_
        )
    RETURN
        CONCATENATEX ( contacts_, [Person], ", " )

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

  • camargos88's avatar
    camargos88
    Community Champion

    Anonymous ,

     

    Try this measure:

    _Contact = 
    VAR _person = SELECTEDVALUE('Table'[Person])
    VAR _tblAreaDate = SELECTCOLUMNS(ADDCOLUMNS(SUMMARIZE(FILTER(ALL('Table'), 'Table'[Person] = _person), 'Table'[Area], 'Table'[Date]), "Combine", COMBINEVALUES(",", 'Table'[Area], 'Table'[Date])), "Combine", [Combine])
    VAR _tblMatch = CALCULATETABLE(
                    VALUES('Table'[Person]), FILTER(ALL('Table'), COMBINEVALUES(",", 'Table'[Area], 'Table'[Date]) in _tblAreaDate && 'Table'[Person] <> _person))
    
    
    RETURN CONCATENATEX(_tblMatch, 'Table'[Person], ",")