Examples
These hands-on SAQL examples walk you through writing a query to retrieve data
-
Use SAQL date functions for advanced time-based analysis.
-
Calculate How Long Activities Take
Use
daysBetween()anddate_diff()to calculate the difference between two dates or times. -
Display the Opportunities Closed This Month
Use relative date ranges to filter opportunities closed in the current month.
-
Forecast Future Data Points with timeseries
Use existing data to predict what might happen in the future.
-
Combine Data from Multiple Data Streams with cogroup
You can combine data from two or more data streams into a single data stream using
cogroup. The data streams must have at least one common field. -
Replace Null Values with coalesce()
When you use a left outer or full outer
cogroupTo blend data, unmatched data comes through as null. Usecoalesce()To replace null values with the value of your choice. -
Dynamically Display Your Top Five Reps with Windowing
Windowing functions perform calculations over a dynamic range.
-
You can append data from two or more data streams into a single data stream using
union. The data streams must have the same field names and structure. -
Calculate the Slope of the Regression Line
Use SAQL to perform linear analysis on your data to find the line that best fits the data. Then use .
regr_slopeto return the slope of this line. -
Show the Top and Bottom Quartile
Use SAQL to calculate percentiles, like the top and bottom quartile of your data.
-
Calculate Grand Totals and Subtotals with the rollup Modifier and grouping() Function
Calculate subtotals of grouped data in your SAQL query using the
rollupmodifier on thegroup bystatement, then work with subtotaled data usinggrouping(). For example, to see the subtotaled value of opportunities by type and lead source, roll up the type and lead source groups. Then, label the subtotals with the grouping function.