Functions & Aggregates

The aggregate, string, and date functions you'll reach for most often when writing foreach ... generate clauses.

Functions & Aggregates

Aggregates

sum, avg, min, max, count, and count_distinct are the core aggregates, always used inside a foreach ... generate:

q = foreach q generate 'Region' as 'Region',
  sum('Amount') as 'TotalRevenue',
  count_distinct('AccountId') as 'Accounts';

String & math helpers

concat(), upper(), lower(), and standard arithmetic (+ - * /) work inline:

q = foreach q generate concat('Region', " - ", 'StageName') as 'Label';

Ordering & limiting

q = order q by 'TotalRevenue' desc;
q = limit q 10;

Combined, this is the classic "top 10 regions by revenue" query pattern.

What you'll learn next

Next: debugging SAQL in the Query Editor when a chart returns the wrong numbers.