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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
NOVICE02
Helper III
Helper III

Define Top N by multiple columns

Hi,
Hoping for some direction. Never done this before and in a time crunch

I have a table of names with certain measures like below. there are 100's of names. I need to highlight the Top N names. First by C%, then d% then r%

 

is it possible to do this? and change the ordering depending on the ask. the measures would remain the same,

 

NameC%d%r%
tt20%45%25%
tr10%55%24%
rt5%75%26%
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Seems than is enough the only Table.MaxN function to get the expected result, when the values are positive:

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZLLDcQgDER7QdpbDtg4fGqJ0gSify3YbDRhuVhiXmZiY67LteYOx/7Tq5yjcq/30UHtB1JwGhADdThUSabHaRh62Oh10RPkbHTrKALIGKQOkoxEo4SURP2AC4TtSV1J8JBm0kLaPyFI2xJNyxEJgycnu3RBop4yb1EnHWM/HZBnm55eSBdmG/shXNlEwRdEDRFbf68XENh+kh50fwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"C%" = _t, #"d%" = _t, #"r%" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"C%", Percentage.Type}, {"d%", Percentage.Type}, {"r%", Percentage.Type}}),
    besten = Table.MaxN(#"Changed Type",{"C%"},10)
in
    besten

 

 

 

image.png

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdFbDoQgDAXQvZDMn5PQ8l6LcROE/UfoVac4/DSxx15e+25aM5th++nVh1G512PrUPsHCQSAB9QxIZ2EfrwGRv/rFlDfkFTSChA15h/JU5bMkM+akOZJKMofXHTemuofOasD0XtRWxDpwCUhMEdNrKdywgt4TZgq15XKkcf5f9sgy7gHmkwSCS94m37C25wt2tpkjF2GKdMxFkqPHSc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"C%" = _t, #"d%" = _t, #"r%" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"C%", Percentage.Type}, {"d%", Percentage.Type}, {"r%", Percentage.Type}}),
    tBestTen=Table.FirstN(Table.Sort(#"Changed Type",{"C%","d%","r%"}),10)
in
   tBestTen
Anonymous
Not applicable

Seems than is enough the only Table.MaxN function to get the expected result, when the values are positive:

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZLLDcQgDER7QdpbDtg4fGqJ0gSify3YbDRhuVhiXmZiY67LteYOx/7Tq5yjcq/30UHtB1JwGhADdThUSabHaRh62Oh10RPkbHTrKALIGKQOkoxEo4SURP2AC4TtSV1J8JBm0kLaPyFI2xJNyxEJgycnu3RBop4yb1EnHWM/HZBnm55eSBdmG/shXNlEwRdEDRFbf68XENh+kh50fwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"C%" = _t, #"d%" = _t, #"r%" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"C%", Percentage.Type}, {"d%", Percentage.Type}, {"r%", Percentage.Type}}),
    besten = Table.MaxN(#"Changed Type",{"C%"},10)
in
    besten

 

 

 

image.png

 

 

Jimmy801
Community Champion
Community Champion

Hello @NOVICE02 

 

I don't know if I get you right. Check out this solution. Depending on the variable "Task" the table is sorted differently. Just change the variable "Task" accordingly to change the result.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKilR0lEyMlAFkiamINIISMbqACWKgBxDsIQpRMIEIlEE0gEWMYeImwHFYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"C%" = _t, #"d%" = _t, #"r%" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"C%", Percentage.Type}, {"d%", Percentage.Type}, {"r%", Percentage.Type}}),
    //Variable for ordering c, d or r allowed
    Task = "d", 
    Top2N = if Task = "c" then 
        Table.FirstN(Table.Sort(#"Changed Type", {{"C%", Order.Descending}}),2) else
        if Task = "d" then 
        Table.FirstN(Table.Sort(#"Changed Type", {{"d%", Order.Descending}}),2) else
        if Task = "r" then 
        Table.FirstN(Table.Sort(#"Changed Type", {{"r%", Order.Descending}}),2) else "wrong task variable"
in
    Top2N

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors