cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
trdoan Member
Member

Count Distinct from different tables + Find matching values

Hi everyone,

 

Here is my sample data.

 

The 3 sheets are my 3 tables where the "General Info" table has all Store Names and the other 2 tables have several Store Names which have 1-to-many relationship through column "Store".

 

I have:

  • 2 Card visuals to count distinct the number of Stores in 'NDT' & 'Laboratory'
  • a "StoreName" slicer created from 'General Info' [Store]

Question 1:

Is there a way to COUNT DISTINCT the number of Stores and RETURN "0" in those 2 Cards if the selection made from the StoreName slicer does not exist in 'NDT' or 'Laboratory'?

 

Ex: If Z is selected from StoreName slicer, the Count result should return 0 instead of  the default (Blank)

 

 

Question 2:

a. If T is selected from the StoreName slicer and  Ultrasonic is selected from the NDT slicer, is it possible to have Power BI showed "No alternate Store can do Ultrasonic"

b. If H is selected from the StoreName slicer and STI is selected from the NDT slicer, it it possible to show:

  • Count of alternatives to the selected Store = 2
  • List of alternate Stores = E ; T

 

Can anyone please show me how to tackle this? Thank you so much!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Count Distinct from different tables + Find matching values

Hi @trdoan,

 

Create the following measures:

 

Distintc Count Laboratory =
IF (
    DISTINCTCOUNT ( NDT[Store] ) = BLANK ();
    0;
    DISTINCTCOUNT ( Laboratory[Store] )
) + 0



Distintc Count NDT =
IF (
    DISTINCTCOUNT ( Laboratory[Store] ) = BLANK ();
    0;
    DISTINCTCOUNT ( NDT[Store] )
) + 0



NDT Alternatives Count =
IF (
    CALCULATE ( COUNT ( NDT[NDT] ); ALLSELECTED ( NDT[NDT] ) ) <> 1;
    DISTINCTCOUNT ( NDT[Store] )
)



NDT No alternatives =
IF (
    CALCULATE ( COUNT ( NDT[NDT] ); ALLSELECTED ( NDT[NDT] ) ) = 1;
    "No alternate Store can do : "
        & CONCATENATEX ( NDT; SELECTEDVALUE ( NDT[NDT] ); "," );
    "Alternative Stores: " & CONCATENATEX ( NDT; NDT[Store]; "," )
)

 

Check PBIX file attach.

 

Regards,

MFelix



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

Proud to be a Datanaut!




View solution in original post

6 REPLIES 6
Super User
Super User

Re: Count Distinct from different tables + Find matching values

Hi @trdoan,

 

Create the following measures:

 

Distintc Count Laboratory =
IF (
    DISTINCTCOUNT ( NDT[Store] ) = BLANK ();
    0;
    DISTINCTCOUNT ( Laboratory[Store] )
) + 0



Distintc Count NDT =
IF (
    DISTINCTCOUNT ( Laboratory[Store] ) = BLANK ();
    0;
    DISTINCTCOUNT ( NDT[Store] )
) + 0



NDT Alternatives Count =
IF (
    CALCULATE ( COUNT ( NDT[NDT] ); ALLSELECTED ( NDT[NDT] ) ) <> 1;
    DISTINCTCOUNT ( NDT[Store] )
)



NDT No alternatives =
IF (
    CALCULATE ( COUNT ( NDT[NDT] ); ALLSELECTED ( NDT[NDT] ) ) = 1;
    "No alternate Store can do : "
        & CONCATENATEX ( NDT; SELECTEDVALUE ( NDT[NDT] ); "," );
    "Alternative Stores: " & CONCATENATEX ( NDT; NDT[Store]; "," )
)

 

Check PBIX file attach.

 

Regards,

MFelix



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

Proud to be a Datanaut!




View solution in original post

trdoan Member
Member

Re: Count Distinct from different tables + Find matching values

Hello @MFelix many thanks to your help! However, I noticed a few things which I've noted on the file here.

 

My Power BI version at work isn't up-to-date so I couldn't open your file, therefore I don't know if there're many differences in the problems I found compared to your file.

 

Please advise! Thank you sooo much!

Super User
Super User

Re: Count Distinct from different tables + Find matching values

What version are you on?

I can try and make a file in your version.

Regards,
MFelix


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

Proud to be a Datanaut!




trdoan Member
Member

Re: Count Distinct from different tables + Find matching values

@MFelix  it's September 2018. Thank you!!!

Highlighted
Community Support Team
Community Support Team

Re: Count Distinct from different tables + Find matching values

Hi @trdoan 

I believe MFelix's solution may help you.

I would suggest you to download the lastest version of Power BI which updates with more new features and fixes many issues occured in previous version.

Also it is backwords compatible. so don't worry about previous pbix files, you can use the lastest version to open and manage these.

 

Best Regards

Maggie 

trdoan Member
Member

Re: Count Distinct from different tables + Find matching values

Hi @MFelix  & @v-juanli-msft , thank you for your help! MFelix's answer worked perfectly on my new version!!! Thanks again!!!

Helpful resources

Announcements
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 136 members 1,490 guests
Please welcome our newest community members: