Forum Discussion
Add new column into data table with space using existing column
- 1 year ago
You can create a calculated column. However, you'll need to ensure the Text Wrap for your values is off
Here is an approach in Power Query that uses non-breaking spaces (unicode 160). Non-breaking spaces won't get collapsed like regular spaces do in certain contexts (like when displayed in row headers). I added some inputs (LevelWeight, LevelLookup) that let you assign/update spacing a little more easily and transparently.
You can see how this works if you paste into Advanced Editor in Power Query. You can copy the relevant steps over to your own query, just be sure to update for column name differences. It's possible to do something very similar with DAX in a calculated column if needed.
let
Source = Table.FromColumns(
{{"Type 1","Type 2","Type 3","Type 4","Type 5","Type 6"}},
type table [Accounts = text]
),
LevelWeight = 3,
LevelLookup = [ Type 1 = 0, Type 2 = 2, Type 3 = 1, Type 4 = 1, Type 5 = 0, Type 6 = 0 ],
AddExpectedResult =
Table.AddColumn(
Source,
"Expected result",
each Text.Repeat(
Character.FromNumber( 160 ) ,
Record.Field( LevelLookup, [Accounts] ) * LevelWeight
) & [Accounts],
type text
)
in
AddExpectedResult
Table in Power Query:
Put into a matrix and you can see that spacing is not collapsed.
Note that to have [Expected result] ignore the spacing when sorting, you will need to set the column's 'Sort by column' setting to [Accounts].
- Snagalapur1 year agoHelper IV
Thank you so much for taking time on this.