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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Solution Authors