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,
I have a calculated table, in which I want the NAME column (all unique) to sort by CATEGORY first, and then sorted alphabetically second. Like this:
NAME | CATEGORY Nr. | *My custom sorting column* | (The desired sorting result, based on custom sorting column ) |
A | 1 | 1001 | first position |
B | 2 | 2003 | third |
C | 1 | 1002 | second |
D | 3 | 3004 | fourth |
E | 4 | 4006 | sixth |
F | 3 | 3005 | fifth |
I managed to make the output for the custom sorting column:
My custom sorting column =
RANKX ( 'Table' ; 'Table'[NAME] ; ; ASC )
+
( 1000 * 'Table'[CATEGORY Nr.] )
But I can't use this column to sort NAME! This gives a circular dependancy error. So the order of the names is used for the RANKX function, which is then used to order the names.
Any suggestions?
Solved! Go to Solution.
Hi,
If possible, one of ways is to create sort column in power query editor.
Please check the below picture and the attached pbix file.
let
Source = source,
#"Sorted Rows" = Table.Sort(Source,{{"CATEGORY Nr.", Order.Ascending}, {"NAME", Order.Ascending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"CATEGORY Nr."}, {{"Count", each Table.AddIndexColumn( _, "index",1,1)}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"NAME", "index"}, {"NAME", "index"}),
#"Added Custom" = Table.AddColumn(#"Expanded Count", "sort_order", each [#"CATEGORY Nr."]*1000 + [index]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"index"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"NAME", type text}, {"sort_order", Int64.Type}})
in
#"Changed Type"
Wow thank you, that must help a lot of people. Unfortunately I'm working with a calculated table. But I'll try to add the column to the original source table and get back to you.
Hi,
If possible, one of ways is to create sort column in power query editor.
Please check the below picture and the attached pbix file.
let
Source = source,
#"Sorted Rows" = Table.Sort(Source,{{"CATEGORY Nr.", Order.Ascending}, {"NAME", Order.Ascending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"CATEGORY Nr."}, {{"Count", each Table.AddIndexColumn( _, "index",1,1)}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"NAME", "index"}, {"NAME", "index"}),
#"Added Custom" = Table.AddColumn(#"Expanded Count", "sort_order", each [#"CATEGORY Nr."]*1000 + [index]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"index"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"NAME", type text}, {"sort_order", Int64.Type}})
in
#"Changed Type"
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.
User | Count |
---|---|
14 | |
9 | |
7 | |
7 | |
6 |
User | Count |
---|---|
21 | |
11 | |
10 | |
9 | |
8 |