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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
derickyy
Frequent Visitor

Unpivot Table but Auto Generate New Rows

Hi,

 

Can you please help me with the following table manipulation? It would be best if it can be achieved through power query but dax query is also acceptable.

 

Basically, I have one table with persons' names and their starte_number and end_number values. I want to create rows with numbers that fall into the start_number and end _number range for each person.

 

Please refer to the tables below:

 

Raw data:

PersonStart NumberEnd Number
A26
B35
C14
D58


Output:

PersonNumber
A2
A3
A4
A5
A6
B3
B4
B5
C1
C2
C3
C4
D5
D6
D7
D8


Please let me know if anyone has any thoughts on this. Thanks in advance!

1 ACCEPTED SOLUTION
edhans
Community Champion
Community Champion

Here you go @derickyy 

This:

edhans_0-1658280358928.png

becomes this

edhans_1-1658280372157.png

Here is the full M code, and then I'll explain what I did.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTICYjOlWJ1oJScgyxiITcE8ZyDLEIhNwDwXsLiOkoVSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, #"Start Number" = _t, #"End Number" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Number", Int64.Type}, {"End Number", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Range", each {[Start Number]..[End Number]}),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Person", "Range"}),
    #"Expanded Range" = Table.ExpandListColumn(#"Removed Other Columns", "Range")
in
    #"Expanded Range"

 

Ignore the SOURCE row. That is just me pasting in your sample data.

I changed the start/end to integers.

The custom column I added a range using a list. So {1..5} will give me a list of 1, 2, 3, 4, 5. So your start/end numbers looked like this:

edhans_2-1658280495400.png

Then I only kept the Person and new Range column.

Finally, I expanded the Range to new rows.

edhans_3-1658280547497.png

 

Any questions, let me know!

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Community Champion
Community Champion

Here you go @derickyy 

This:

edhans_0-1658280358928.png

becomes this

edhans_1-1658280372157.png

Here is the full M code, and then I'll explain what I did.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTICYjOlWJ1oJScgyxiITcE8ZyDLEIhNwDwXsLiOkoVSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, #"Start Number" = _t, #"End Number" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Number", Int64.Type}, {"End Number", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Range", each {[Start Number]..[End Number]}),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Person", "Range"}),
    #"Expanded Range" = Table.ExpandListColumn(#"Removed Other Columns", "Range")
in
    #"Expanded Range"

 

Ignore the SOURCE row. That is just me pasting in your sample data.

I changed the start/end to integers.

The custom column I added a range using a list. So {1..5} will give me a list of 1, 2, 3, 4, 5. So your start/end numbers looked like this:

edhans_2-1658280495400.png

Then I only kept the Person and new Range column.

Finally, I expanded the Range to new rows.

edhans_3-1658280547497.png

 

Any questions, let me know!

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.