FAQ: Add a number of rows

Add an arbitrary number of rows to a table based on a column value of type Number.

Try the sample app!

For this example, the table from which the row-addition process will be initiated is called Control Table. The table to which new rows will be added is called Target Table. Use your own names as you see fit. Note that they could even be the same table. Control Table must allow updates; Target Table must allow adds.

Control Table must have at least two columns for this process: Finish Count (type Number; the number of rows needed; may be virtual); and Add Count (type Number; the number of the next row to add; may not be virtual). Column names may be changed as desired.

Finish Count should have Required? set to ON. Add Count should be blank or zero.

Action 1: Add Rows for Remaining Count

This is the action that you should invoke to add the rows: it does everything.

  • For a record of this table: Control Table
  • Do this: Grouped: execute a sequence of actions
  • Actions: (added below, after creating actions 2, 3, and 4)
  • Only if this condition is true: OR(ISBLANK([Add Count]), ([Add Count] < [Finish Count]))

Action 2: Increment Count

This manages the Add Count column value, which contains the number of the next row to add. It’ll start at 1 and increment to Finish Count.

  • For a record of this table: Control Table
  • Do this: Data: set the values of some columns in this row
  • Set these columns:
    • Add Count: ([Add Count] + 1)
  • Only if this condition is true: TRUE (or blank)

Action 3: Add Row For This Count

This action adds one row to the Target Table table for the current value of the Control Table row’s Add Count column.

  • For a record of this table: Control Table
  • Do this: Data: add a new row to another table using values from this row
  • Table to add to: Target Table
  • Set these columns:
    • (columns as desired)
  • Only if this condition is true: TRUE (or blank)

Action 4

This action implements a loop by recursively performing action (1) for each successive number in the indicated range, from 1 to Finish Count.

  • For a record of this table: Control Table
  • Do this: Data: execute an action on a set of rows
  • Referenced Table: Control Table
  • Referenced Rows: LIST([_THISROW])
  • Referenced Action: (action 1)
  • Only if this condition is true: TRUE (or blank)

Action 1

Return to action (1) and add actions (2), (3), and (4) to its Actions list.

  • Actions:
    • (action 2)
    • (action 3)
    • (action 4)
12 Likes

Very interesting, I’ll try I was looking for something like this, it would be great if there is a way to update if number already exist.

Thanks for this tip. I was looking for something like this, to add rows, for a monthly budget (I have to create/add the next 12 months, one month per row…). This does the job.

As a newby, some problems are not intuitive. Could be nice if appsheet add an action to mimic ‘for each/do while/repeat until/’ to do this more easily.

1 Like

This seems like a much simpler approach than this:

Is it the same result or am I missing something?

IN my case [Finish Count] is a VC that counts the elements on a list type column,
What if I want each of the new rows to have one of the different elements of that list? Is that possible?

i.e.
[Example] (List type column): A, B, C, D, E
[Finish count]=5
New rows: image

1 Like

@Nicolas_Feldman
Try this:

1 Like