---
schema_version: "1"
id: f829361afec392dad02c36cf3f5776144bf06ac631d0bfea8c31beaf44b1c30b
title: coalesce
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/reference/bi-saql-functions-coalesce.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-functions-coalesce.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 555b990bd2d9ed7f8ed609a281e77a4aa70bfaece330fbe312d9e484ac408070
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# coalesce

Use `coalesce()` to get the first non-null value from a list of parameters, or to replace nulls with a different value.

```nolang
coalesce(value1 , value2 , value3 , ... )
```

The arguments must all be convertible to a common data type, which will be the type of the result.

This function is often used to substitute a default value for null values when data is retrieved for display. For example:

`SELECT COALESCE(description, short_description, '(none)') ...`

The above example  returns `description` if it is not null, otherwise `short_description` if it is not null, otherwise `(none)`.

## Example: Left Outer Cogroup with coalesce()

A left outer cogroup combines the right data stream with the left data stream. If a record on the left stream does not have a match on the right stream, the missing right value comes through as null. To replace null values with a different value, use `coalesce()`.

For example, suppose that you have a dataset of meeting information from the Salesforce Event object, and you join it with data from the Salesforce Opportunity object. This shows amount won with the total time spent in meetings.

```nolang
ops = load "Ops";
meetings = load "Meetings";
q = cogroup ops by 'Account' left, meetings  by 'Company' ;
q = foreach q generate ops.'Account' as 'Account', sum(ops.'Amount') as 'sum_Amount', sum(meetings.'MeetingDuration') as 'TimeSpent';
```

It looks like we had no meetings with Zen Retreats.

![Diagram showing the meeting dataset.](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_coalesce_1.png)

Let’s use `coalesce()` to change that null value to a zero.

```nolang
ops = load "Ops";
meetings = load "Meetings";
q = cogroup ops by 'Account' left, meetings  by 'Company' ;

–-use coalesce() to replace null values with zero
q = foreach q generate ops.'Account' as 'Account', sum(ops.'Amount') as 'sum_Amount', coalesce(sum(meetings.'MeetingDuration'), 0) as 'TimeSpent';
```

![Diagram showing the meeting dataset.](https://developer.salesforce.com/media/bi_dev_guide_saql/bi_saql_coalesce_2.png)
