---
schema_version: "1"
id: 9cb4d1522a6de4e125d351f6900002ca09ce7bb484e39635b957b83408e89dba
title: Examples
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/concept/bi-saql-examples.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d57d943b11b1b69d692ee5edd6cca2220e55ad976fd1923b3dcf18cc2f8e396d
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# Examples

These hands-on SAQL examples walk you through writing a query to retrieve data

- **[Analyze Your Data Over Time](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-dates.md)**


    Use SAQL date functions for advanced time-based analysis.

- **[Calculate How Long Activities Take](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-daysbetween.md)**


    Use `daysBetween()` and `date_diff()` to calculate the difference between two dates or times.

- **[Display the Opportunities Closed This Month](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/reference/bi-saql-functions-date-examples.md)**


    Use relative date ranges to filter opportunities closed in the current month.

- **[Forecast Future Data Points with timeseries](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-timeseries.md)**


    Use existing data to predict what might happen in the future.

- **[Combine Data from Multiple Data Streams with cogroup](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-cogroup.md)**


    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()](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-coalesce.md)**


    When you use a left outer or full outer `cogroup` To blend data, unmatched data comes through as null. Use `coalesce()` To replace null values with the value of your choice.

- **[Dynamically Display Your Top Five Reps with Windowing](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-top5.md)**


    Windowing functions perform calculations over a dynamic range.

- **[Append Datasets using union](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-union.md)**


    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](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-stats.md)**


    Use SAQL to perform linear analysis on your data to find the line that best fits the data. Then use .`regr_slope` to return the slope of this line.

- **[Show the Top and Bottom Quartile](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-topbotquartile.md)**


    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](https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-examples-rollup-grouping.md)**


    Calculate subtotals of grouped data in your SAQL query using the `rollup` modifier on the `group by` statement, then work with subtotaled data using `grouping()`. 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.
