Button to duplicate multiple rows

Hello,

I have a complex action to perform
I can split it in 3 steps

first my setup:
I have a table with items
and a second table with price evolutions with these columns
item / date / price element 1 / price element 2 / price
this is a big simplification (because it is around 23 columns with elements I need to calculate price)

so the 3 steps I need
1/ filter the second table with the latest entry for each item (some items have more rows then others, and the latest dates are not all the same)

2/ duplicate all these rows

3/ in the duplicate rows, change the date to today and change one other row to certain value (same for all duplicate rows)

is it possible to perform this with a button?
just doing one separate step would be great as well
I can’t even figure out any of these steps on it’s own (even the filter one)

thanks

Let me know whether the embedded doc is along the lines of what you were looking for.
There are a few different principles that I like to use that accomplish kind of what I think your asking for. By copying the doc to your work-space you can check out the formulas used.

Hi @Joshua_Upton,

Thank you
really cool, I learned so much from looking at the formula’s.( especially how you calculate the ID, i didn’t know you could use filtering to calculate a rowid.

I understand the filtering now

I need some time to try to understand the duplicate formula.

a few questions:
1/ in the filtered table, Why not use this formula
thisRow.ID=thisTable.Filter(Item = thisRow.Item).ID.Max()
so you don’t need the extra column (or is there a good reason I don’t know yet).

2/ some pointers to understand the duplicate formula would be helpfull
for example: I need the duplicate rows to be added in the original unfiltered table
the .nth element I can’t figure out
and in the addrow reference they only set one column

thanks

pieter

1/ I had originally had it with this formula, but I pulled the example here from another table that I had created for my own use case, where it had to have a count so feel free to use either.

2/ The .Nth() is necessary because of the way Coda’s ‘CurrentValue’ scopes. The reference within a FormulaMap() is local to the list you want affected, so by duplicating to a separate table you would lose the reference to the original table’s elements. Using Sequence() and .Nth() allows us to use the elements within the original table at the Nth() location to affect the ‘CurrentValue’ of the separate table. This is the only way I have figured out how to implement a loop within a loop.
A post on this subject that helped me: Loop within a Loop
I am not sure if there has been any updates that allows a different system of looping, but someone may correct me on that.

As for the AddRow Reference, the reference does only show 1 column being affected, however the actual formula takes optional parameters: .AddRow(table, column 1, columnValue 1, column 2*, columnValue 2*, column 3*, columnValue 3 …) and so on.
This allows you to duplicate any information within a row that you want, and leave out anything that is not necessary to duplicate.
I have long been waiting for a simple DuplicateRow(table, row, table 2*…) but unless I have been out of the loop, I am still waiting.

Indeed. Here’s a versatile way to loop:

It may not always be needed though. E.g., here’s a different approach that could be used e.g. if you need to iterate over a product of 2+ lists. It’s a live calculation, no action required:

As for copying over the row, here’s a handy trick (see the video):

thx @Joshua_Upton for explaining and @Paul_Danyliuk for adding more info.

some things are still a bit to complicate for me at this time, but i’m digging in.

I agree that a simple duplicate row function should be there

1 Like

I also need a simple buttom to duplicate a row. In my use case, my customer uses Coda to build a table for BOMs (bill of materials) and the corresponding part numbers of the parts in Coda. It happens frequently that a singe part needs to be updated. Using a duplicate button would allow to duplicate the marked row with one click. The previous version will be set inactive then (manually or by formular).

Sharing an example doc with what you are hoping to accomplish would help us help you!

I can do later this week.

Probably a button formula similar to this would work

RunActions(
  thisTable.AddRow([Column Name], thisRow.[Column Name], ...)
  thisRow.ModifyRows(done?, true)
)
1 Like

hi! This is similar to what I need. Were you able to find a solution?