News / Totals, averages and counts inside your automations

Totals, averages and counts inside your automations

Plenty of automations need a number before they can do anything useful. How much is this customer's open balance? How many tickets are still waiting? What did we sell per month this year? Until now the answer meant fetching the records and adding them up in a loop, one row at a time, like an accountant with an abacus.

The new Aggregate Records step does the arithmetic for you. Pick a table, choose Count, Sum, Average, Minimum or Maximum, add the same filters you already use in Query Records, and save the result to a variable.

Want a breakdown instead of one number? Set Group by and you get one value per group: revenue by stage, tickets by assignee, orders by customer. Date fields can group by day, week, month or year, so "sales per month" is one step. Loop over the groups with For Each (it now has an optional Each key as name for the group), or read one directly, like {{totals.Won}}.

In code it is one function, records_aggregate():

$open = records_aggregate("invoices", "sum", "amount", [
    ["field" => "status", "op" => "=", "value" => "Open"]
]);