Forum

Repeat table rows b...
 
Notifications
Clear all

Repeat table rows based on the value in last column

3 Posts
2 Users
0 Reactions
270 Views
(@vidak)
Posts: 2
New Member
Topic starter
 

Hello everyone,

I am using pq often to unpivot tables but i have a situation where i would actually like to "unpivot" a table by repeating table rows based on a value in the last column.

In att is a simple example

I would very much appreciate if anyone could help with this and it would be perfect if this could be done in power query, but any other suggestion (vba or other) is more than welcome!

 

Thanks,

Vidak

sample.JPG

 
Posted : 03/06/2018 5:10 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Vidak,

You can simply add a column with this formula:

=Text.Repeat("a",[Column5])

In column 5 should be the count you want for rows to be duplicated.

Then, from transform tab, split the new column by number of characters, use 1 char split, but from advanced settings, make sure you split into rows, not into columns, this will duplicate all other columns.

Now you can remove the additional column, to diplay only the results.

I can be done with custom M code, with List.Accumulate, but it's easier via interface, see the attached file.

 
Posted : 07/06/2018 2:09 am
(@vidak)
Posts: 2
New Member
Topic starter
 

Dear Catalin,

Thanks so much! Simple and smooth 🙂

This saves me so much time, you re the best!

 

Vidak

 
Posted : 24/06/2018 4:25 pm
Share: