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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
SB13
New Member

Ranking based on a distinct count of a particular column ignoring other columns

I have several columns. Column1  contains 'category'. Column2 contains sub category showing yes and no options. Column 3 has sub sub category showing Y and N option. Column 4 has IDs. I want to have top 10 categories based on distinct count of IDs filtered 'yes' for sub category and Y for sub sub category.

There is also a coloumn which shows grades.The table must contain grades column but the top 10 caculation shoould be based on the distinct count of IDs using the filters and not based on grades too. Can somebody please help me with this complex issue. Many thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @SB13 ,

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

vjiewumsft_0-1710140326189.png

2.Create the new column to filter yes for sub category and Y for sub sub category. Add the field to filter pane and set the value is 1.

 

yes_Y_category = IF(AND('Table'[sub category] = "yes", 'Table'[sub sub category] = "Y"), 1, 0)

 

vjiewumsft_1-1710140346888.png

3.Create the measure to distinct ID.

 

Discou_ID = SUMX('Table', DISTINCTCOUNT('Table'[ID]))

 

4.Create the measure to rank.

 

Rank_categ = RANKX(ALL('Table'[Category]), [Discou_ID],,DESC,Dense)

 

5.Drag the measure into the table visual. The result is shown below.

vjiewumsft_2-1710140430339.png

Best Regards,

Wisdom Wu

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

2 REPLIES 2
Anonymous
Not applicable

Hi @SB13 ,

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

vjiewumsft_0-1710140326189.png

2.Create the new column to filter yes for sub category and Y for sub sub category. Add the field to filter pane and set the value is 1.

 

yes_Y_category = IF(AND('Table'[sub category] = "yes", 'Table'[sub sub category] = "Y"), 1, 0)

 

vjiewumsft_1-1710140346888.png

3.Create the measure to distinct ID.

 

Discou_ID = SUMX('Table', DISTINCTCOUNT('Table'[ID]))

 

4.Create the measure to rank.

 

Rank_categ = RANKX(ALL('Table'[Category]), [Discou_ID],,DESC,Dense)

 

5.Drag the measure into the table visual. The result is shown below.

vjiewumsft_2-1710140430339.png

Best Regards,

Wisdom Wu

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

 

 

 

 

 

 

 

Sahir_Maharaj
Super User
Super User

Hello @SB13,

 

Can you please try this approach:

 

1. Create a Measure for Distinct Count of IDs

DistinctCountFilteredIDs = 
CALCULATE(
    DISTINCTCOUNT(YourTable[ID]), 
    YourTable[SubCategory] = "yes",
    YourTable[SubSubCategory] = "Y"
)

2. Create a Measure for Ranking Categories

RankCategories = 
RANKX(
    ALL(YourTable[Category]), 
    [DistinctCountFilteredIDs], 
    , DESC, Dense
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.