COALESCE
The first of its arguments that is not blank.
Group: Logical. Compatible with DAX.
Syntax
COALESCE ( <expression1>, <expression2> [, <expression3>] … )
| Parameter | Type | Description |
|---|---|---|
expression1 | Value | The first value to try. |
expression2 | Value repeatable | The value to use when the one before is blank; more may follow. |
Returns
Same type as its values. The first of the values that is not blank, or BLANK when they all are.
Remarks
- The values are tried from left to right, and those after the first one that is not blank are never evaluated.
- Empty text and 0 are values, not blanks:
COALESCE ( "", "x" )is empty text. COALESCE ( a, b )is the short way to writeIF ( ISBLANK ( a ), b, a ).COALESCE ( [Measure], 0 )shows 0 instead of nothing, but then every row has a value: a visual orSUMMARIZECOLUMNSno longer leaves out the rows with no data, and a table of products by day can grow to every product on every day.
Examples
The first value that is there
EVALUATE
ROW (
"Blank, 5", COALESCE ( BLANK (), 5 ),
"Blank, 0, 7", COALESCE ( BLANK (), 0, 7 ),
"All blank", COALESCE ( BLANK (), BLANK () )
)
| Blank, 5 | Blank, 0, 7 | All blank |
|---|---|---|
| 5 | 0 | (blank) |
Zero for missing liters
EVALUATE
VAR Orders =
DATATABLE ( "Product", STRING, "Liters", INTEGER, { { "Pils", 120 }, { "Cider", BLANK () } } )
RETURN
ADDCOLUMNS ( Orders, "Liters or 0", COALESCE ( [Liters], 0 ) )
| Product | Liters | Liters or 0 |
|---|---|---|
| Pils | 120 | 120 |
| Cider | (blank) | 0 |
Every row shows
The same measure as on the BLANK page, now with 0 for the products under the limit.
EVALUATE
SUMMARIZECOLUMNS (
Products[Product],
"Big sellers", COALESCE ( IF ( [Liters sold] > 500000, [Liters sold] ), 0 )
)
ORDER BY Products[Product]
| Products[Product] | Big sellers |
|---|---|
| Cider | 0 |
| IPA | 0 |
| Lettøl | 0 |
| Pils | 1004326 |
Related functions
ISBLANK, IF, BLANK, SELECTEDVALUE, DIVIDE.