OpenBI Docs Buy

EARLIER

A column's value in an outer row context: the one before, or a number of levels out.

Group: Filter. Compatible with DAX.

Syntax

EARLIER ( <column> [, <number>] )
ParameterTypeDescription
columnColumnThe column whose value in an outer row context is wanted.
numberNumber
optional
How many row contexts to go out; 1, the one just outside, when left out.

Returns

Same type as the column. The column's value in that outer row.

Remarks

  • It is needed when two iterations go over the same table, so that the column's name alone means the inner row: FILTER ( Products, Products[Price per liter] > EARLIER ( Products[Price per liter] ) ) compares every product with the outer row's.
  • Without an outer row context that has the column it is an error: in a measure on its own, or with only one iteration.
  • With a number it goes out that many row contexts: EARLIER ( column, 2 ) reads the row two iterations out.
  • A variable usually reads better: store the outer row's value with VAR before the inner iteration starts, and compare with the variable. The second example shows both giving the same.

Examples

A price rank and a count per category

EVALUATE
ADDCOLUMNS (
    Products,
    "Price rank", COUNTROWS ( FILTER ( Products, Products[Price per liter] > EARLIER ( Products[Price per liter] ) ) ) + 1,
    "Same category", COUNTROWS ( FILTER ( Products, Products[Category] = EARLIER ( Products[Category] ) ) )
)
ORDER BY Products[Price per liter] DESC
Products[Product]Products[Category]Products[Price per liter]Price rankSame category
IPABeer6413
CiderCider5221
PilsBeer3833
LettølBeer3043

The same rank with a variable

EVALUATE
ADDCOLUMNS (
    Products,
    "With EARLIER", COUNTROWS ( FILTER ( Products, Products[Price per liter] > EARLIER ( Products[Price per liter] ) ) ) + 1,
    "With a variable",
        VAR Price = Products[Price per liter]
        RETURN COUNTROWS ( FILTER ( Products, Products[Price per liter] > Price ) ) + 1
)
ORDER BY Products[Price per liter] DESC
Products[Product]Products[Category]Products[Price per liter]With EARLIERWith a variable
IPABeer6411
CiderCider5222
PilsBeer3833
LettølBeer3044

EARLIEST, FILTER, ADDCOLUMNS, RANKX, SUMX.

Last updated · OpenBI Studio 0.3.74