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

How to Take Count and Distinct Count Dependent on Column Value

In my data set I need to take a count or distinct count of a unqiue ID depending on a column value.  In the below example, if the Value is A or C I need to take a count of the Unique ID and if the Value is B I need to take a distinct count.  The Expected Result is what I would need the data to be represented as in a single visualization.  Any help would be greatly appreciated as I keep going in circles.

 

Data Example  
    
ValueIDUnique IDCount Type
A12345A12345Count
A12345A12345
A12345A12345
B13579B13579Distinct
B13579B13579
B54321B54321
B54321B54321
B97531B97531
C11223C11223Count
C99887C99887

 

Expected Result
  
ValueTotal
A3
B3
C2
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @pranit828 ,

 

I took what you provided and was able to tweak it a little to get what I needed.  Here is where I ended up at when creating the measure.  Thanks for the assistance.

 

Count =
SWITCH( SELECTEDVALUE('Table'[Value]),
"A", COUNT('Table'[Unique ID]),
"B", DISTINCTCOUNT( 'Table'[Unique ID]),
"C", COUNT('Table'[Unique ID]))
 
Regards,
Eric

View solution in original post

4 REPLIES 4
pranit828
Community Champion
Community Champion

Hi @Anonymous 

Use matrix chart instead of table chart

Or

Create is as a column instead of measure.





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile
Anonymous
Not applicable

Hi @pranit828 ,

 

I took what you provided and was able to tweak it a little to get what I needed.  Here is where I ended up at when creating the measure.  Thanks for the assistance.

 

Count =
SWITCH( SELECTEDVALUE('Table'[Value]),
"A", COUNT('Table'[Unique ID]),
"B", DISTINCTCOUNT( 'Table'[Unique ID]),
"C", COUNT('Table'[Unique ID]))
 
Regards,
Eric
pranit828
Community Champion
Community Champion

HI @Anonymous 

 

You can try 
_count = 
Switch(TRUE(),

            'A',COUNT(COL),

            'B',DISTINCTCOUNT(COL),

            'C',COUNT(COL))





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile
Anonymous
Not applicable

Hi @pranit828 ,

 

I am able to create a measure with the formula suggested, but when adding the measure to a visual I receive the following error "Function 'SWITCH' does not support comparing values of type True/False with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values."

 

Regards,

Eric

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.