A rollup adds up (or counts, averages, or finds the smallest or largest of) a number from a list of records. This recipe gets the project of a changed task, collects all tasks of that project, rolls up their hours, and saves the sum on the project. It's meant to keep totals correct without a manual count.
What you'll need
A
Projectsdatabase app with aTotal hoursnumber field.A
Tasksdatabase app with aHoursnumber field and a relation field toProjects.
Build the automation
Open the
Tasksapp and click the automations icon at the top right (Create and view automations).Select
New automation, then selectWhen a record is updated.In the trigger, select the field name. Tape preselects one of the app's fields. Select
HoursunderFIELDS, then select the preselected field again to remove it.Select
Add action→Get related. The action readsGet related records for the current record.Next to
From app, chooseProjects, thenOutgoing viaand the relation field toProjects. KeepAll records. This follows the task to its project.Select
Add follow, chooseTasksnext toFollow to app, thenIncoming viaand the same relation field. This follows the project back to all of its tasks.Select
Add action→Rollup collected. In the sentenceRollup collected values from {field} calculate {type} and save in Rollup, selectHoursas the field andSumas the calculation. ClickRollupand rename the variable toTotal hours.Select
Add action→Update related. It readsUpdate all related records. Choose theProjectsapp.Select
Add fieldand chooseTotal hours. SelectSet valueand insert theTotal hoursvariable from the rollup.Open the
•••menu ofUpdate relatedand check thatTrigger automationsis off (the default), so the update can't start other automations on the project.Select
Create automation.
Note:
Mind the size. A collection holds at most 1,000 records. A project with more tasks gets a total that's too low, without a warning.
Avoid loops. Don't start an automation on
Projectsthat changes tasks, or the two can call each other.
The result
When someone changes the Hours of a task, the Total hours of its project is recalculated from all tasks, for example 42.5.
Variations
Choose
Count allinstead of the sum to count the tasks of a project.Choose
Averageinstead ofSumto show the average time per task. Other calculations includeMedian,Min, andMax.Skip the rollup. In
Update recordorCreate record, a number field can useLookupinstead ofSet value: pick a number field of a related database app and chooseSum.Run the same steps on
When a record is createdto include new tasks.
Learn more
FAQs
Can I use a calculation field instead?
Can I use a calculation field instead?
Often, yes. Add a calculation field to Projects. In the calculation editor, type @, find the related database, for example ↙ Tasks via Project if the relation field is called Project, and select Sum of Hours. The total updates on its own. Use the automation instead if only some tasks should count, or if you need the total in a regular number field.
Why is the total wrong after I delete a task?
Why is the total wrong after I delete a task?
The automation runs when a task changes, not when one is deleted. To keep the total correct after a delete, recalculate it from the project, or use a calculation field.
Are you a developer using the Tape API for automations?
Are you a developer using the Tape API for automations?
The automation API has its own documentation for developers. Full reference: rollup_iterable_values in the developer docs →
Still have questions? Find answers and get help from community experts in the Tape community →
