Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Expand Tier Number to Tier Number List?

Hello everyone,

I have a table like this

3Tier 1
6Tier 2
10Tier 3

15

Tier 4

How can I expand the table into this:

1Tier 1
2Tier 1
3Tier 1
4Tier 2
5Tier 2
6Tier 2
7Tier 3
8Tier 3
9Tier 3
10Tier 3
11Tier 4

Thanks in advance!

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlbSUQrJTC1SMFSK1YlWMoNxjcBcQwMY3xjCN4XxTZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Till = _t, Tier = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "From", each try #"Added Index" [Till] { [Index]  - 1 } otherwise "1", type number),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each if [From]="1" then 1 else Number.FromText([From])+1),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"Till", Int64.Type}, {"Custom", Int64.Type}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type", "Custom.1", each {[Custom]..[Till]}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom2", "Custom.1"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"From", "Index", "Till", "Custom"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom.1", "Tier"})
in
    #"Reordered Columns"

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may apply the following transformations in 'Advanced Editor'.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlbSUQrJTC1SMFSK1YlWMoNxjcBcQwMY3xjCN4XxTZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}}),
    Custom1 = Table.TransformColumns(
     #"Changed Type",
     {"Column1",each 
     let x=List.Max(List.Select(#"Changed Type"[Column1],(x)=>x<_)),
     start=if x=null then 1 else x+1,
     end=_ 
     in 
     List.Generate(
         ()=>start,
         each _<=end,
         each _+1
     )
     }
),
    #"Expanded Column1" = Table.ExpandListColumn(Custom1, "Column1"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Column1",{{"Column1", Int64.Type}})
in
    #"Changed Type1"

 

Result:

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may apply the following transformations in 'Advanced Editor'.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlbSUQrJTC1SMFSK1YlWMoNxjcBcQwMY3xjCN4XxTZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}}),
    Custom1 = Table.TransformColumns(
     #"Changed Type",
     {"Column1",each 
     let x=List.Max(List.Select(#"Changed Type"[Column1],(x)=>x<_)),
     start=if x=null then 1 else x+1,
     end=_ 
     in 
     List.Generate(
         ()=>start,
         each _<=end,
         each _+1
     )
     }
),
    #"Expanded Column1" = Table.ExpandListColumn(Custom1, "Column1"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Column1",{{"Column1", Int64.Type}})
in
    #"Changed Type1"

 

Result:

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlbSUQrJTC1SMFSK1YlWMoNxjcBcQwMY3xjCN4XxTZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Till = _t, Tier = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "From", each try #"Added Index" [Till] { [Index]  - 1 } otherwise "1", type number),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each if [From]="1" then 1 else Number.FromText([From])+1),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"Till", Int64.Type}, {"Custom", Int64.Type}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type", "Custom.1", each {[Custom]..[Till]}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom2", "Custom.1"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"From", "Index", "Till", "Custom"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom.1", "Tier"})
in
    #"Reordered Columns"

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
HotChilli
Super User
Super User

In Power Query, create a new blank query.

Paste this :

= {1..15}

This will create a list of 1-15.

Convert it to a table (from menu).

Make sure data type is whole number.

Then Merge this table with the original table (using Left join, on the number column).

You'll get a 2 column table (1st column is number 1-15, 2nd column is 'table').

Expand the the second column to return the text with "tier..".

Sort the first column (to ensure it is ascending).

Use 'Fill Up' on the second column.

 

Good luck.

 

mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it in the query editor.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlbSUQrJTC1SMFSK1YlWMoNxjcBcQwMY3xjCN4XxTZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, Tier = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Number", Int64.Type}, {"Tier", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each List.Repeat({[Tier]}, try (if [Number] = List.Max(#"Added Index"[Number]) then 1 else [Number] - #"Added Index"{[Index]-2}[Number]) otherwise [Number] - 0)),
    Custom1 = List.Combine(#"Added Custom"[Custom]),
    #"Converted to Table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Index1" = Table.AddIndexColumn(#"Converted to Table", "Index", 1, 1, Int64.Type),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Index1",{"Index", "Column1"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Column1", type text}})
in
    #"Changed Type1"

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors