Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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,
Name | C% | d% | r% |
tt | 20% | 45% | 25% |
tr | 10% | 55% | 24% |
rt | 5% | 75% | 26% |
Solved! Go to Solution.
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
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
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
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.