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

Count unique/distinct values from two different tables

I have two columns in two different tables.
1) Accounts[Account Name]
2) Visits[Regarding Account]

 

I want to count how many unique/distinct values from Visits[Regarding Account] are on Accounts[Account Name].

 

Thx

Thomas

1 ACCEPTED SOLUTION

Hi  @Anonymous ,

 

Using below dax expression:

 

Measure = CALCULATE(DISTINCTCOUNT(Visits[Regarding Account]),ALL(Visits))-CALCULATE(DISTINCTCOUNT(Visits[Regarding Account]),FILTER(ALL(Visits),Visits[Regarding Account] in FILTERS(Accounts[Account Name])))

 

And you will see:

v-kelly-msft_0-1613024583222.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

 

View solution in original post

5 REPLIES 5
robinHH
Frequent Visitor

Hi!


if the tables have no relationship you can use the treatas function within an calculate function. 

The treatas function filters the visitor function from my example by the values from the account name table. Afterwards, only the distinct values are calculated by the measure.

Capture.PNG

 

I hope I was able to help you 🙂

Best wishes
Rob

Anonymous
Not applicable

Hi Rob! @robinHH 
Thanks for your contribution. 
Unfortunately I receive below error. As I see it we also need to select column for the "account" table. Currently it's just referring to the table but does not point to column 🙂

tvarberg_0-1612941106806.png

 

Hi  @Anonymous ,

 

Using below dax expression:

 

Measure = CALCULATE(DISTINCTCOUNT(Visits[Regarding Account]),ALL(Visits))-CALCULATE(DISTINCTCOUNT(Visits[Regarding Account]),FILTER(ALL(Visits),Visits[Regarding Account] in FILTERS(Accounts[Account Name])))

 

And you will see:

v-kelly-msft_0-1613024583222.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

 

Anonymous
Not applicable

@amitchandak , yes - please have a look below.
In this example the result should be 1.
Skærbæk VVS 25326598 4780 Stege is there two times but Visits[Regarding Account] should be unique/distinct values and then look how many values are on Accounts[Account Name]

 

Visits[Regarding Account]Accounts[Account Name]
Skærbæk VVS 25326598 4780 StegeEskebjerg-Mørkøv VVS 4440 Mørkøv
Skærbæk VVS 25326598 4780 Stege​Bent VVS 2300 København S
Sanistål A/S Centrallager Billund 7190 Billund​NITO-TEK A/S - ( Skovhavens VVS A/S ) Skovhavens VVS A/S 5270 Odense N
Brødrene A. & O. Johansen A/S 4000 Roskilde2B VVS Teknik Aps 31274753 2620 Albertslund
Brødrene A. & O. Johansen A/S 4300 HolbækSkærbæk VVS 25326598 4780 Stege
amitchandak
Super User
Super User

@Anonymous , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

If they are joined you can use distinctcount( Visits[Regarding Account])

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.