Create rows from columns

I have a customer code and 4 columns that contain product orders


I need to create a csv with a line per customer code for each one of the product codes
eg, if Customer 1234 wants 3 of each of the 4 colours, the table needs to create 4 rows for that customer, one for each product.

I cant work out how to generate rows from columns

Hey James,

There’s ways to get this done, it just depends on exactly how you want the resulting table to look.

Option A

Results looks like this:
Screen Shot 2022-08-15 at 9.46.07 AM

To get something like that, here’s what you’d do:

To break that down:

  1. Take your separate columns of color quantities and create a new column that concatenates them altogether. (This will let us split into rows in future step)

  1. Remove the color columns that were in your source data

  1. Split your new column into rows, on commas, so that each color:quantity pair gets its own row (but keeps the account number its associated with)

Screen Shot 2022-08-15 at 9.50.59 AM

  1. Then, split the color:quantity pair into columns, on the colon character, so that quantity is in its own column.

  1. Then rename your columns for clarity.

Option B

The easier method, which might well do what you need, is to flip the table.

That will get you a result like this:

This is all you’d need to do:

Screen Shot 2022-08-15 at 9.53.10 AM

Hope that helps!


Brian Dawson
Automation Consultant

3 Likes

Thanks Brian
Option A worked fantastically and opened my eyes to a couple of other use cases as well.
Appreciate your help

1 Like