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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX count unique values after union

Hi everybody,

I am trying to create measure counting unique values of particular column, which is the result of UNION of two columns with similar data from two diffrent tables. It looks much easier with example 🙂  

post.PNG

It is not my buisness caase, but similar to it.  My tables have different structure, so I can perform UNION only over columns. And the issues is that DISTINCOUNT works only with column, and in my case I can specify particular column name after UNION statement.

Please help me with this case.

Thank you in advance!

4 REPLIES 4
felipegm10
New Member

Hey, I had the same problem before but I got the solution. Use this measure, it's simple and works fine:

Measure=  COUNTROWS(DISTINCT(UNION(VALUES(Table1[sales_manager]),VALUES(Table2[manager))))

v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can create new measure.

 

Measure = var t=DISTINCT(UNION(SELECTCOLUMNS(Table1,"column1",Table1[sales_manager]),SELECTCOLUMNS(Table2,"column1",Table2[manager])))

return COUNTX(t,[column1])

 

6.png 

 

 

 

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @v-xicai ,

Thank you for the reply! 

Unfortunately DISTINCT doesn't want to accept table expression after UNION statement...

Maybe something like this:

Manager # =
VAR ManagerTable1 =
    DISTINCT ( Table1[sales_manager] )
VAR ManagerTable2 =
    DISTINCT ( Table2[manager] )
VAR CombinedManagers =
    UNION ( ManagerTable1, ManagerTable2 )
VAR UniqueManagers =
    DISTINCT ( CombinedManagers )
RETURN
    COUNTROWS ( UniqueManagers )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.