SAQL Queries

Learn the basics of SAQL — the Salesforce Analytics Query Language — to load, filter, group, and aggregate your data.

SAQL Queries

SAQL (Salesforce Analytics Query Language) powers every lens and dashboard. The UI writes it for you, but learning it unlocks advanced calculations.

The query pipeline

SAQL reads like a pipeline. Each line transforms a stream and assigns it back to q:

q = load "Opportunities";
q = filter q by 'StageName' == "Closed Won";
q = group q by 'Region';
q = foreach q generate 'Region' as 'Region', sum('Amount') as 'Revenue';

Grouping and aggregating

group defines the buckets and foreach ... generate produces the output columns. Common aggregations are sum(), avg(), count(), and unique().

Ordering and limiting

Use order q by 'Revenue' desc and limit q 10 to return a clean "top 10" result.

What's next

Next you'll turn these queries into interactive dashboards and predictions.