cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
sharpedogs
Advocate II
Advocate II

DAX - count unique values in one column, the filter it by a different table and column

I should be able to figure this out, but I'm stumped..

 

Table 1 

- has login info with the principal piece of data being "User Name". There are alot of "User Name" duplicates beucase each day the user logs in it generates a new row.

 

Table 2

- Is a file with "User Name", all unique users. 

 

** There are users in the Table 1 that are not in Table 2 and there are Users in Table 2 that are not in Table 1. 

 

I want to write a DAX that counts all the unique "User Name" from the first table and then filters it to match the users in the Second. The output is a unique Set of Users that are in both tables..

 

I've tried multiple, calcualte, countdistinct and filter formulas but nothing seems to work... please help 🙂  

 

 

2 ACCEPTED SOLUTIONS
JarroVGIT
Resident Rockstar
Resident Rockstar

Well this is an interesting question. You say you want a set of users to be returned so I assumed you are aware you want a calculated table. Please note that typically it helps us a lot if you create some copyable dummy data for us to experiment with 🙂

I created the following tables:

Table UsersTable UsersTable LoginsTable Logins

These tables have a 1-many relationship on UserID. I then created the following table;

 

UniqueJoins = 
VAR _loginsID = SELECTCOLUMNS(Logins, "LoginID", Logins[UserID])
VAR _usersID = SELECTCOLUMNS(Users, "UserID", Users[UserID])
VAR _union = ADDCOLUMNS(UNION(_loginsID, _usersID), "IsInBothTables",
     VAR _curID = [LoginID]
     RETURN
     IF(COUNTROWS(FILTER(Users, Users[UserID] = _curID)) > 0 && 
        COUNTROWS(FILTER(Logins, Logins[UserID] = _curID)) >0, TRUE, FALSE))

RETURN
DISTINCT(FILTER(_union, [IsInBothTables] = TRUE()))

This returns the following set:

image.png

As you can see, both userID C and D are left out as well as YY and Z as they only occur in their own tables but not the other one.

Does this help? You can see my pbix here (ignore other tables as they are for other questions).

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

ohhhh..... mercy.... Yes...

 

I would give you two thumbs up if i could

View solution in original post

2 REPLIES 2
JarroVGIT
Resident Rockstar
Resident Rockstar

Well this is an interesting question. You say you want a set of users to be returned so I assumed you are aware you want a calculated table. Please note that typically it helps us a lot if you create some copyable dummy data for us to experiment with 🙂

I created the following tables:

Table UsersTable UsersTable LoginsTable Logins

These tables have a 1-many relationship on UserID. I then created the following table;

 

UniqueJoins = 
VAR _loginsID = SELECTCOLUMNS(Logins, "LoginID", Logins[UserID])
VAR _usersID = SELECTCOLUMNS(Users, "UserID", Users[UserID])
VAR _union = ADDCOLUMNS(UNION(_loginsID, _usersID), "IsInBothTables",
     VAR _curID = [LoginID]
     RETURN
     IF(COUNTROWS(FILTER(Users, Users[UserID] = _curID)) > 0 && 
        COUNTROWS(FILTER(Logins, Logins[UserID] = _curID)) >0, TRUE, FALSE))

RETURN
DISTINCT(FILTER(_union, [IsInBothTables] = TRUE()))

This returns the following set:

image.png

As you can see, both userID C and D are left out as well as YY and Z as they only occur in their own tables but not the other one.

Does this help? You can see my pbix here (ignore other tables as they are for other questions).

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ohhhh..... mercy.... Yes...

 

I would give you two thumbs up if i could

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors