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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
powerbidev123
Solution Sage
Solution Sage

Get distinct count of names based on a table visual

I am having a table visual something like below:

NameScore
A12
A33
B22
B44
C13
C11

 

This table visual gets filtered by a slicer and the values get changed. There is a measure used in the table visual on visual level basis.

 

Problem Statement:

How can I get the count of the distinct names in a card Visual as per the slicer selection?

5 ACCEPTED SOLUTIONS

Hi @mark_endicott , I tried this before the number is not changing upon slicer selection

View solution in original post

@mark_endicott  I have used a calculated table and created a column with distinct names in it  since I needed to use it in a measure which basically creates an 'AND' operation in slicer selection for multiple values

 

Names_selected=DISTINCT('Query1'[Name]) -- this is calculated table for the unique names
 
-- below is the measure for the 'AND ' operation on slicer selection
 
Measure =
IF (
    ISFILTERED ( Names_selected[Name])
        && MAX ( Query1[Name] )
            IN ALLSELECTED ( Names_selected[Name] )
                && COUNTROWS ( Names_selected)
                    <= CALCULATE (
                        COUNT ( Query1[Name] ),
                        FILTER (
                            ALLSELECTED ( Query1),
                            [Name]
                                IN ALLSELECTED ( Names_selected[Name] )
                                    && [Email] = MAX ( Query1[Email] )
                        )
                    ),
    1
)
 
 
I tried  adding this measure also in the card visual level filter so that the 'Query1'  table names can come as unique but the measure value I am unable to apply as it seems to be locked kind of thing. The same measure value I was able to apply it in the table visual 

View solution in original post

@powerbidev123 - I'm sorry it's not clear why you need the calculated table. 

 

DISTINCTCOUNT( Query1[Name] ) will count the number of items selected, if the slicer uses the Query1[Name] column, therefore it will use your AND operation if there are two Names selected, see below:

 

mark_endicott_0-1717175339497.png

It is however clear why your measure is not working. you are just asking it to produce the value 1 if your condition is TRUE, also your use of MAX will only ever take one value. 

 

You have now introduced Email into your measure, so there is no way I can solve this without some sample data, and all the other measures that may contribute to this. 

View solution in original post

Hi @mark_endicott ,  you are right on the part that max gives only 1 or 0 value. Let me reframe the question  a bit.  

EmailSkillNameScore
aAmazon RDS2
aAutomotive1
dAmazon RDS1
dAutomotive2
gAmazon RDS2
gAutomotive2

 

Now I have put a slicer on SkillName in a separate query which gives distinct names

Dax used:  DISTINCT('Query1'[SkillName])
powerbidev123_0-1717499864279.png

 

 
this above column I am using it in the AND operation measure in my main  query where the email, skillname,score reside which is as below:
Measure =
IF (
    ISFILTERED ( SkillsSelected[SkillName])  
        && MAX ( Query1[SkillName] )
            IN ALLSELECTED ( SkillsSelected[SkillName] )
                && COUNTROWS ( SkillsSelected)
                    <= CALCULATE (
                        COUNT ( Query1[SkillName] ),
                        FILTER (
                            ALLSELECTED ( Query1),
                            [SkillName]
                                IN ALLSELECTED ( SkillsSelected[SkillName] )
                                    && [Email] = MAX ( Query1[Email] )
                        )
                    ),
    1
)
 
 
Now the issue is the AND operation is working fine upon selecting from slicer but I need to display the count of the unique email in a separate card visual which I am unable to do as the measure gives only value as 1. The count in card visual that I need is 3 since 3 such unique emails are there which have both the Skills. 

View solution in original post

@mark_endicott , used the separate calculated table to store the distinct skill name. so that it can be used in the 'AND' created measure . 

 

You are right that we can do it without even creating a calculated table but the main issue is how to get that measure to reflect in the count card

View solution in original post

9 REPLIES 9
mark_endicott
Super User
Super User

@powerbidev123 - Try this

 

DISTINCTCOUNT( 'Table'[Name] )

 

If this works, please accept it as the solution. 

Hi @mark_endicott , I tried this before the number is not changing upon slicer selection

@powerbidev123 - Then you need to provide more information about what column you have in your slicer. 

 

Does it come from the same table?

How does it relate to the Name column? 

If it is from a different table, is there a relationship between the tables?

If you have Name in the slicer and it is in the same table, it works fine:

 

mark_endicott_0-1717173824269.png

 

@mark_endicott  I have used a calculated table and created a column with distinct names in it  since I needed to use it in a measure which basically creates an 'AND' operation in slicer selection for multiple values

 

Names_selected=DISTINCT('Query1'[Name]) -- this is calculated table for the unique names
 
-- below is the measure for the 'AND ' operation on slicer selection
 
Measure =
IF (
    ISFILTERED ( Names_selected[Name])
        && MAX ( Query1[Name] )
            IN ALLSELECTED ( Names_selected[Name] )
                && COUNTROWS ( Names_selected)
                    <= CALCULATE (
                        COUNT ( Query1[Name] ),
                        FILTER (
                            ALLSELECTED ( Query1),
                            [Name]
                                IN ALLSELECTED ( Names_selected[Name] )
                                    && [Email] = MAX ( Query1[Email] )
                        )
                    ),
    1
)
 
 
I tried  adding this measure also in the card visual level filter so that the 'Query1'  table names can come as unique but the measure value I am unable to apply as it seems to be locked kind of thing. The same measure value I was able to apply it in the table visual 

@powerbidev123 - I'm sorry it's not clear why you need the calculated table. 

 

DISTINCTCOUNT( Query1[Name] ) will count the number of items selected, if the slicer uses the Query1[Name] column, therefore it will use your AND operation if there are two Names selected, see below:

 

mark_endicott_0-1717175339497.png

It is however clear why your measure is not working. you are just asking it to produce the value 1 if your condition is TRUE, also your use of MAX will only ever take one value. 

 

You have now introduced Email into your measure, so there is no way I can solve this without some sample data, and all the other measures that may contribute to this. 

Hi @mark_endicott ,  you are right on the part that max gives only 1 or 0 value. Let me reframe the question  a bit.  

EmailSkillNameScore
aAmazon RDS2
aAutomotive1
dAmazon RDS1
dAutomotive2
gAmazon RDS2
gAutomotive2

 

Now I have put a slicer on SkillName in a separate query which gives distinct names

Dax used:  DISTINCT('Query1'[SkillName])
powerbidev123_0-1717499864279.png

 

 
this above column I am using it in the AND operation measure in my main  query where the email, skillname,score reside which is as below:
Measure =
IF (
    ISFILTERED ( SkillsSelected[SkillName])  
        && MAX ( Query1[SkillName] )
            IN ALLSELECTED ( SkillsSelected[SkillName] )
                && COUNTROWS ( SkillsSelected)
                    <= CALCULATE (
                        COUNT ( Query1[SkillName] ),
                        FILTER (
                            ALLSELECTED ( Query1),
                            [SkillName]
                                IN ALLSELECTED ( SkillsSelected[SkillName] )
                                    && [Email] = MAX ( Query1[Email] )
                        )
                    ),
    1
)
 
 
Now the issue is the AND operation is working fine upon selecting from slicer but I need to display the count of the unique email in a separate card visual which I am unable to do as the measure gives only value as 1. The count in card visual that I need is 3 since 3 such unique emails are there which have both the Skills. 

@powerbidev123 I'm sorry it is still completely unclear why you need the calculated table for SkillName, and cannot use the SkillName column from your Query1 table, then simply do:

 

 

DISTINCTCOUNT(Query1[Email])

 

 

Can you explain why this didnt work? it is not clear from your sample data. 

@mark_endicott , used the separate calculated table to store the distinct skill name. so that it can be used in the 'AND' created measure . 

 

You are right that we can do it without even creating a calculated table but the main issue is how to get that measure to reflect in the count card

@powerbidev123 - So your use of  MAX ( Query1[SkillName] ) is the problem, because it will only ever find one value in this table, which when unfiltered in the data you have supplied is "Automotive". If you were to apply a filter to this table, that value will change, but it will only ever be the last value alphabetically.

 

So, your DAX will show 1 when Automotive is selected, (blank) when Amazon RDS is selected and 1 if both are - if you replace the 1 with DISTINCTCOUNT(Query1[Email]) you will see 3 instead of 1, but still (blank) when Amazon RDS is selected in the slicer because it is not the MAX value. 

 

The way you are trying to do this, you cannot specify multiple values so replacing MAX with VALUES will not work. 

 

I think this is trying to be too complex, and I'm not sure why you need to be.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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