adding rows based on quanity column

jag2005

New Member
Joined
Oct 1, 2005
Messages
32
Hello - I want to be able to in power query to take a list of records and create new copys of each record based on a quantity column.

As a example, I provided a few fields, but I will like for it to copy the entire row as I have 20+ columns.

Current Result
Item Quantity
1234 2
5678 5

Desired Result
Item Quantity New Quantity
1234 2 1
1234 2 1
5678 5 1
5678 5 1
5678 5 1
5678 5 1
5678 5 1

Thanks in advance.
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I put your small sample into an Excel Table named Table1
- Add the table to Power Query
then...
These are all of the annotated steps to get your results:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", Int64.Type}, {"Qty", Int64.Type}}),

    // Add a list to each row...List starts at 1 and ends at Qty
    #"Added Custom" = Table.AddColumn(#"Changed Type", "New Qty", each {1..[Qty]}),

    // Expand the list...creating new rows
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "New Qty"),

    // Transform the column..running the Sign option (which returns 1 for each positive value)
    #"Extracted Sign" = Table.TransformColumns(#"Expanded Custom",{{"New Qty", Number.Sign, Int64.Type}})
in
    #"Extracted Sign"

Is that something you can work with?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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