EARLIER

The EARLIER function is used on calculated columns and allows access to the value of a column (of the row being analyzed) in nested calculations. In most cases it can be said that the EARLIER function returns an access "to the current row".

Unlike the EARLIEST function, it allows you to specify the level of recursion that it refers to.

Syntax

EARLIER(
    column,
    number
)

Parameters
  • column: Column name or expression that returns a column.
  • number: (Optional) number representing the level of evaluation being considered: the next level is represented by 1, two levels of evaluation are represented by 2, etc. The default value is 1.
Returned value

The EARLIER function returns the value of the current row in the column column corresponding to the number of evaluation levels indicated by the number argument.

If used in a measure, the function returns an error.

Additional Information

The EARLIER function returns an error if there is no row context prior to parsing the table.

Examples

In this example we start from a table of products:

Product table

We can add a calculated column with information about the number of total products with the same name as the one included in the row that is being considered at each moment with the following DAX expression:

Número = 
    COUNTROWS(
        FILTER(
            Products,
            Products[Product] = EARLIER(Products[Product])
        )
    )

EARLIER function

We see how the number of elements whose name matches that of the row being considered is correctly calculated. Let's see how it is applied:

The expression is executed for each of the rows in the table, creating a row context for each of them. Each time this context is created, the EARLIER function allows to return the value that, in that row, takes a column.

Next, the COUNTROWS function is executed to count the number of rows in the result of filtering the Products table, leaving only those rows in which the product matches the one returned by the EARLIER function. In other words, for the first row, for example, the table would be filtered to leave only the products whose name is "A".

Related functions
Category
Filter
Submitted by admin on Sat, 07/06/2019 - 12:20