Use the same data types within a single `coalesce` function. If you want to coalesce values that have different data types:
- Use the SQL `CAST` operator.
-[Change the data type from the Data Model page][cast-data-type].
If you want to use `coalesce` with JSON or JSONB data types, you'll need to flatten the JSON objects first. For more information, look up the JSON functions that are available in your SQL dialect. You can find some [common SQL reference guides here][sql-reference-guide].
## Related functions
This section covers common functions and formulas from other tools that are equivalent to the Metabase `coalesce` expression:
-[SQL](#sql)
-[Spreadsheets](#spreadsheets)
-[Python](#python)
All examples use the custom expression and sample data from the [Consolidating values](#consolidating-values-from-different-columns) example:
| Notes | Comments | `coalesce([Notes], [Comments] "No notes or comments.")` |
| I have a note. | I have a comment. | I have a note. |
| | I have a comment. | I have a comment. |
| I have a note. | | I have a note. |
| | | No notes or comments. |
### SQL
When you ask Metabase a question from the notebook editor or SQL editor, the question is converted into a SQL query that runs against your database or data warehouse.
The Metabase `coalesce` expression is equivalent to a SQL `coalesce` function:
```
SELECT
COALESCE(notes, comments, "no notes or comments")
FROM
sample_table;
```
### Spreadsheets
If we assume that "Notes" is in column A, and "Comments" is in column B, we can achieve basic coalesce functionality by combining `IF` statements with functions like `ISBLANK` (for empty values) or `ISNA` (for "NaN" values).
Note that this formula doesn't generalize well if you're working with more than two columns. In those cases, you may be used to working with `INDEX` and `MATCH` in an array formula (or maybe considering [a move away from spreadsheets][spreadsheets-to-bi] entirely!).
```
=IF(ISBLANK($A2),$B2,IF(ISBLANK($B2),$A2,"No notes or comments."))
```
### Python
For those of you that come from the [pandas][pandas] and [numpy][numpy] world, let's assume our sample data is in a dataframe object called `df`.
Coalesce-esque `pandas` functions include `combine_first()` and `fillna()`: