FIRSTNONBLANK
The first of a column's values, in their order, for which an expression is not blank.
Group: Time intelligence. Compatible with DAX.
Syntax
FIRSTNONBLANK ( <column>, <expression> )
| Parameter | Type | Description |
|---|---|---|
column | Column | The column whose values are gone through, in their sort order: dates, numbers or text. A table of one column works too: VALUES ( Periods[Month] ), or one made in the query, such as a variable's or CALENDAR's. |
expression | Expression evaluated for each row | Tried for each value until it is not blank; usually a measure. |
Returns
Table. The first value of the column for which the expression is not blank, as a table of one row.
Remarks
- The values are those visible in the filter context, smallest first: dates from the earliest, text in alphabetical order.
- The expression sees each value as a row, not as a filter. A measure turns the row into a filter by itself; a plain aggregation such as
SUM ( Ledger[Amount] )does not, and then every value passes: wrap it inCALCULATE. - When no value qualifies, the table is empty and shows as blank.
- Over a table made in the query, the expression reads the table's column in each row, as in example 3.
- For the expression's value itself rather than the column's, use
FIRSTNONBLANKVALUE.
Examples
The first month with a booked amount, by scenario
The forecast starts in 2026.
EVALUATE
SUMMARIZECOLUMNS (
Ledger[Scenario],
"First month", FIRSTNONBLANK ( Periods[Month], [Booked amount] )
)
ORDER BY Ledger[Scenario]
| Ledger[Scenario] | First month |
|---|---|
| Actual | 2024-01-01 |
| Budget | 2024-01-01 |
| Forecast | 2026-01-01 |
On a column of product names
The first and last product, in alphabetical order, that has liters sold.
EVALUATE
ROW (
"First", FIRSTNONBLANK ( Sales[Product], [Liters sold] ),
"Last", LASTNONBLANK ( Sales[Product], [Liters sold] )
)
| First | Last |
|---|---|
| Cider | Pils |
Over a table made in the query
The days come smallest first whatever order they are written in: the first day over 1 is 2, the last below 3 is 2.
EVALUATE
VAR Days = DATATABLE ( "Day", INTEGER, { { 3 }, { 1 }, { 2 } } )
RETURN
ROW (
"First over 1", FIRSTNONBLANK ( Days, IF ( [Day] > 1, [Day] ) ),
"Last below 3", LASTNONBLANK ( Days, IF ( [Day] < 3, [Day] ) )
)
| First over 1 | Last below 3 |
|---|---|
| 2 | 2 |