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
Shailu198
Helper I
Helper I

Top N and Bottom N in single chart

Hi,

 

I want to show Top N and bottm N using single chart in Power BI? Any help would be appreciated.

 

Regards,

Shailesh

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Shailu198

 

You can use a simple power query to do that:

 

let
    SortedTable = Table.Sort(Persons, {"Age"}),
    Top_N = Table.FirstN(SortedTable, 3),
    Last_N = Table.LastN(SortedTable, 3),
    Combined_Table = Table.Combine({Top_N, Last_N})
in
    Combined_Table

First, sort the table by the column that you want. Then, take the Top_N and Last_N ( 3, in my example) and finally combine them.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi Shailesh,
Did this solution work for you? Can you please share a screenshot (masking the data except the numbers) in here?
Thanks,
Bhoga
Anonymous
Not applicable

Hi, @Shailu198

 

You can use a simple power query to do that:

 

let
    SortedTable = Table.Sort(Persons, {"Age"}),
    Top_N = Table.FirstN(SortedTable, 3),
    Last_N = Table.LastN(SortedTable, 3),
    Combined_Table = Table.Combine({Top_N, Last_N})
in
    Combined_Table

First, sort the table by the column that you want. Then, take the Top_N and Last_N ( 3, in my example) and finally combine them.

Hi Caaarlos,

 

I don't have a direct column to sort the values, i need to do aggregration (like sum, count) and based on that it need to sort.

The method you mentioned is working fine for columns where we can sort direct. 

I tried like this - 

SortedTable = Table.Sort(Persons, {"count(Age)"}),

but this is not working. Any other help would really help me.

 

Thanks,

Shailesh

Anonymous
Not applicable

Hi, @Shailu198, I can't answer you right now, and I have to text my solution. But, for now try to create a function to count how many times a value appers

 

 

let
  MY_COUNT_FUNC = (VALUE_TO_COUNT, as text) =>
    List.Count(List.Select(Table.Column(TABLE, VALUE_TO_COUNT)))

Add a new column to you real table:

 

 

 

Table.AddColumn(My_Table, "Count", each MY_COUNT_FUNC(_))

And finally, sort your matrix.

 

Hope it helps, and sorry, but I really can't make a real solution for now. 

 

Hi Caaarlos,

 

Thanks for your reply. will try to achieve through the method you told.

Thanks 🙂 

 

 

Regards,

Shailesh

Shailu198
Helper I
Helper I

Hi,

 

How to show the Top N and Bottom N both in a single chart in Power BI? Is any option or workaround available for it?

Thanks in advance.

 

Regards,

Shailesh

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.