Forum

How to add or dupli...
 
Notifications
Clear all

How to add or duplicate rows based on the values of a column?

6 Posts
5 Users
0 Reactions
484 Views
(@jycccwjc)
Posts: 64
Estimable Member
Topic starter
 

How can I add or duplicate rows when the value of a column is "Yes"? In this example, I wan to add or duplicate rows 7,8,9 based on "yes" on the Pge1.Split column.

 

Thanks!

 
Posted : 23/04/2020 12:44 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Jim,

One way is to duplicate the query and filter the Pge1.Split column to retain rows containing 'Yes', then merge the two queries As New. Or you could add a custom column:

= if [Pge1.Split] ="Yes" then "1-2" else null)

And split the new column by delimiter and in the advanced settings choose split into 'Rows'.

Mynda

 
Posted : 24/04/2020 12:53 am
(@bluesky63)
Posts: 162
Estimable Member
 

Hi Mynda

Amazing,  didn't know can split into row with conditions,  there will be a lot of use case for me

Thank you !

 

Jim

Attached an sample for you

 
Posted : 24/04/2020 2:54 am
(@mynda)
Posts: 4761
Member Admin
 

Glad I could help, Jim 🙂

 
Posted : 24/04/2020 6:12 am
(@jase71ds)
Posts: 1
New Member
 

Mynda, the second answer you gave:

Or you could add a custom column: = if [Pge1.Split] ="Yes" then "1-2" else null)

And split the new column by delimiter and in the advanced settings choose split into 'Rows'.

blew my mind!!!

Wow! Thanks so much! I registered in this forum just to tell you how grateful I am for the second solution you presented.

PS - you have fantastic YT videos. Thanks for all you do in teaching us.

Jase.

 
Posted : 20/01/2021 7:58 pm
(@simonf)
Posts: 1
New Member
 

Hi,

Agree that this was very clever and worked for me:

if [Pge1.Split] ="Yes" then "1-2" else null)Smile

 

I went a little further (pasted from advanced view):

#"Add number of rows" = Table.AddColumn(#"Filtered Rows", "Custom", each if [Frequency]="Yes" then Text.Repeat("x",BlankCount) else null),
#"Split Column by Position" = Table.ExpandListColumn(Table.TransformColumns(#"Add number of rows", {{"Custom", Splitter.SplitTextByRepeatedLengths(1), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Custom"),

 

where BlankCount is a number from a named range in the spreadsheet - this number determined the number of repeats required.  e.g. setting this as 3 creates a field value of "xxx"

Split is then by character (again creating rows) so each "x" created a new row.

 

 
 
Posted : 24/04/2021 10:44 pm
Share: