Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

count common values for a columns from two tables

Hi,

I have two tables which has EmailID field, I need to get the count of common EmailIDs from both the tables:

Table1                         

Users
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

 

Table2

ActiveUsers
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

 

I want to compare Users from Table1 to ActiveUsers from Table2 and get the count of only those Users from Table1 which are present in Table2. So, I can get the count of those Users only from Table1 which are active as per Table2.

 

Thanks

  • Anonymous Perhaps:

     

    Measure = COUNTROWS(INTERSECT(SELECTCOLUMNS('Table1',"Users",[Users]),SELECTCOLUMNS('Table2',"Users",[ActiveUsers])))

     

  • Hi Anonymous ,

     

    You can create a measure like below:-

    Measure =
    CALCULATE (
        DISTINCTCOUNT ( _users[Users] ),
        FILTER ( _users, _users[Users] IN VALUES ( _ActiveUsers[ActiveUsers] ) )
    )

     

    Thanks,

    Samarth

10 Replies

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

    Anonymous Perhaps:

     

    Measure = COUNTROWS(INTERSECT(SELECTCOLUMNS('Table1',"Users",[Users]),SELECTCOLUMNS('Table2',"Users",[ActiveUsers])))

     

  • Anonymous , Create a common user table 

    Users = distinct(union(distinct(Table1[Users]),distinct(Table2[ActiveUsers])))

     

    the have two measure

    T1= count(Table1[Users])

    T2 = Count(Table2[Users])

     

    Both in A and B

    both = counts(filter(values(users[User]), not(isblank(T1)) && not(isblank(T2)) ))

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

    Hi Anonymous ,

     

    You can create a measure like below:-

    Measure =
    CALCULATE (
        DISTINCTCOUNT ( _users[Users] ),
        FILTER ( _users, _users[Users] IN VALUES ( _ActiveUsers[ActiveUsers] ) )
    )

     

    Thanks,

    Samarth

  • Anonymous's avatar
    Anonymous
    Not applicable

    Greg_Deckler Thank you for the solution, it works fine.

    As we are getting count here, Can you please help me how to get the list of these common emailids also?

     

    Thanks

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

      Anonymous Replace COUNTROWS with CONCATENATEX(...,[Users],",")

      • Anonymous's avatar
        Anonymous
        Not applicable

        Greg_Deckler , 

        It's giving error when replaced COUNTROWS with CONCATENATEX:

        "Too few arguments were passed to the CONCATENATEX function. The minimum argument count for the function is 2."

        Measure = CONCATENATEX(INTERSECT(SELECTCOLUMNS('Table1',"Users",[Users]),SELECTCOLUMNS('Table2',"Users",[ActiveUsers])))

         

        thanks