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
blinabj
Frequent Visitor

Dynamic table sorting based on total count with fixed value at the bottom

Hi,

 

I want to sort this table dynamically. So that the color category with the highest count is at the top, and the lowest at the bottom, but, I want "Unknown", to always be the last value in the table even though it has a high count. How do I do this? 

Sort.png

Thanks in advance, highly appreciate it 🙂

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

Hi @blinabj ,

 

This is my test table:

vyadongfmsft_0-1667463569968.png

 

Please create two columns:

Count = IF('Table'[ID] = MINX(FILTER('Table','Table'[Category] = EARLIER('Table'[Category])),'Table'[ID]), CALCULATE(COUNT('Table'[Category]),FILTER('Table','Table'[Category] = EARLIER('Table'[Category]))))

Rank = SWITCH(
    TRUE(),
   'Table'[Category] = "Unknown" && 'Table'[Count] <> BLANK(),DISTINCTCOUNT('Table'[Category]),
    'Table'[Count] <> BLANK(),RANKX('Table',[Count],,DESC,Dense))

vyadongfmsft_1-1667463675575.png

 

You can sort by [Rank]:

vyadongfmsft_2-1667463740463.png

 

If you don't want to see Rank column in table visual, you can hide it in Specific column:

vyadongfmsft_3-1667463831009.png

Best regards,

Yadong Fang

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

6 REPLIES 6
v-yadongf-msft
Community Support
Community Support

Hi @blinabj ,

 

This is my test table:

vyadongfmsft_0-1667463569968.png

 

Please create two columns:

Count = IF('Table'[ID] = MINX(FILTER('Table','Table'[Category] = EARLIER('Table'[Category])),'Table'[ID]), CALCULATE(COUNT('Table'[Category]),FILTER('Table','Table'[Category] = EARLIER('Table'[Category]))))

Rank = SWITCH(
    TRUE(),
   'Table'[Category] = "Unknown" && 'Table'[Count] <> BLANK(),DISTINCTCOUNT('Table'[Category]),
    'Table'[Count] <> BLANK(),RANKX('Table',[Count],,DESC,Dense))

vyadongfmsft_1-1667463675575.png

 

You can sort by [Rank]:

vyadongfmsft_2-1667463740463.png

 

If you don't want to see Rank column in table visual, you can hide it in Specific column:

vyadongfmsft_3-1667463831009.png

Best regards,

Yadong Fang

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

 

Hi again @v-yadongf-msft,

 

I have now got 0 values as well (For example for Color: Pink, the Sum of Count = 0). How can I make it work with that?

 

Thanks in advance, highly appreciate it!

It worked, thank you so much for the help! 🙂

lukiz84
Memorable Member
Memorable Member

Count is a measure? 

No, it just an automatic count done by the table of the IDs for each category. Here is the table the data is taken from. So, no measure is used so far.

Table.png

Ok, "Auto count" is a measure too (an implicit measure, not adviced, but ok) 🙂

 

Then i think it's not possible.

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.

Top Solution Authors