Sorting question

LouisT

Board Regular
Joined
Apr 5, 2010
Messages
73
Office Version
  1. 365
Platform
  1. Windows
Hey everyone, just starting to work in Power BI. I've got a Matrix built the way i want, however the column headers are with a strange naming convention for the purpose of sorting them. ex: 01_Blue, 02_Red, 03_Yellow, etc.,
Anyhow, what i'd like is to keep the order based on the numerical value, but have the header ONLY show the colour. Is that doable?

Thanks in advance everyone.
LouisT
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The prefix seems to be 3 characters unless there are more than 99 colors. In this case the following might help:

Power Query:
let
    Source = #table({"01_Blue", "02_Red", "03_Yellow"}, {{1, 2, 3},{2, 3, 4},{3, 4, 5},{4, 5, 6}}),
    RenameColumns = Table.RenameColumns(Source, List.Transform(Table.ColumnNames(Source), each {_, Text.RemoveRange(_, 0, 3)} ))
in
    RenameColumns

If we need to find the underscore position and rename the columns dynamically:

Power Query:
let
    Source = #table({"01_Blue", "02_Red", "03_Yellow"}, {{1, 2, 3},{2, 3, 4},{3, 4, 5},{4, 5, 6}}),
    RenameColumns = Table.RenameColumns(Source, List.Transform(Table.ColumnNames(Source), each {_, Text.RemoveRange(_, 0, Text.PositionOf(_, "_") + 1)} ))
in
    RenameColumns

Edit: You mentioned ordering—if you also need to sort these columns at the end of the table:
Power Query:
let
    Source = #table({"Another Header", "01_Blue", "03_Yellow", "02_Red"}, {{"A", 1, 2, 3},{"B", 2, 3, 4},{"C", 3, 4, 5},{"D", 4, 5, 6}}),
    ExcludedColumns = {"Another Header"},
    ReOrderColumns = Table.ReorderColumns(Source, ExcludedColumns & List.RemoveItems(List.Sort(Table.ColumnNames(Source)),  ExcludedColumns)),
    RenameColumns = Table.RenameColumns(ReOrderColumns, List.Transform(Table.ColumnNames(ReOrderColumns), each {_, Text.RemoveRange(_, 0, Text.PositionOf(_, "_") + 1)} ))
in
    RenameColumns
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top