Forum Discussion
Ordering Columns
- 8 years ago
In Query Editor, bring up your query with the raw data. From the menu, select "Add Column" and then "Conditional Column". In the dialog, you can give this a name like DeptSort and define the conditions. Just keep adding rules until you have all of your values covered. Here is an example of what you will end up with (this is the code that will be written for you):
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRJLUgsKslNzStR0lEyMlCK1YlWikIRNAaL+aKImZiABSNRBM2MlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Departments = _t, Incidents = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Departments", type text}, {"Incidents", Int64.Type}}), #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "DeptSort", each if [Departments] = "ADepartment" then 4 else if [Departments] = "ZDepartment" then 2 else if [Departments] = "MDepartment" then 1 else if [Departments] = "YDepartment" then 3 else 0) in #"Added Conditional Column"After that, you can use Sort By in the Data Model.
OK, in your M code, you are going to need to add a custom column (conditional column) that specifies a number for each of your Departments that is in the order you want them sorted. So, 1, 2, 3, 4. Once you have that, then in your Data Model, you can specify the "Sort By" column for your Departments column and then they will sort in the order that you want them.
I'm sorry, fairly new to all of this. M Code?
- rocky098 years agoSolution Sage
Anonymous
M is nothing but your Query editor (in simple)
check my above updated answer.
- Greg_Deckler8 years agoCommunity Champion
In Query Editor, bring up your query with the raw data. From the menu, select "Add Column" and then "Conditional Column". In the dialog, you can give this a name like DeptSort and define the conditions. Just keep adding rules until you have all of your values covered. Here is an example of what you will end up with (this is the code that will be written for you):
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRJLUgsKslNzStR0lEyMlCK1YlWikIRNAaL+aKImZiABSNRBM2MlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Departments = _t, Incidents = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Departments", type text}, {"Incidents", Int64.Type}}), #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "DeptSort", each if [Departments] = "ADepartment" then 4 else if [Departments] = "ZDepartment" then 2 else if [Departments] = "MDepartment" then 1 else if [Departments] = "YDepartment" then 3 else 0) in #"Added Conditional Column"After that, you can use Sort By in the Data Model.