cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Count distinct value with condition in column

Hi everyone,

I have a datatable and I want to display the top 5 Name with Value >15 and use 1 Slicer to filter the time:

1.JPG

I am a new user of Power BI and I don't know how to make this request, please help me. With Slicer, I know I need to create a list of Measures to perform filtering.

1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following steps to meet your requirement.

 

1. Create a measure to calculate the distinct count value and the value is greater than 15.

 

Measure = CALCULATE(DISTINCTCOUNT(A[Value]),A[Value]>15)

 

2. Then we can put the measure to filter on this visual and filter TOP 5 name.

 

C 1.jpg

 

The result like this,

 

C 2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

View solution in original post

7 REPLIES 7
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following steps to meet your requirement.

 

1. Create a measure to calculate the distinct count value and the value is greater than 15.

 

Measure = CALCULATE(DISTINCTCOUNT(A[Value]),A[Value]>15)

 

2. Then we can put the measure to filter on this visual and filter TOP 5 name.

 

C 1.jpg

 

The result like this,

 

C 2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

Thanks a lot! Saved my life!

amitchandak
Super User
Super User

Create a measure like this

Value GT = Calculate(Sum(Table[Value]),Table[Value]>15)

Use a visual level filter to take the top 5 Name based on the value

 

Ord create a rank and use that in a filter of the visual level filter

Rank = rankx(all(Name),[Value GT ],,dese,dense)

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!
Anonymous
Not applicable

Dear @amitchandak ,

The problem is that my data table has a lot of records, the number of distint names is over 200, I can't create each Measure to count each Name, this can be easily handled if using a custom column to store the number for each Name, but I need to use Measure so that the chart can work with Slicer. 

I can get a list of distinct names, but how do I use the Measure to count the number for each name distinct?

@Anonymous , You can create a table with a distinct name and join the other table with that. You can always use count distinct from name table

 

Name = distinct(Table[Name])

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!
Anonymous
Not applicable

 @amitchandak ,

I created Table B with Distinct Name from Table A, I can also count the number of Distinct Names with CALCULATE COUNTROWS, but so the Slicer I use to filter Year will not work.

 

1.JPG

Please check my pbix file.

test.pbix 

@Anonymous , I created two measures. The COlumn will not respond to changes. You can change count distinct to countrows. One that uses Table A column can one work on one directional relation. One on the table B need bi-directional relation

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

Power BI Dev Camp Session 22 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!