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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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