EARLIER DAX Function in Power BI

The EARLIER() function in Power BI DAX (Data Analysis Expressions) is a row context function used when working with calculated columns, not with measures. It allows you to access the value of a column in a previous row context. This is especially useful when performing row-by-row calculations that depend on values from earlier or outer iterations.

DAX Syntax EARLIER(column_name, number)

The function has the following parameters:

Conceptual Understanding When we use EARLIER(), we are nesting row contexts — for example, using CALCULATE, FILTER, or iterators like SUMX inside a calculated column. DAX maintains a stack of row contexts. EARLIER() gives access to values from outer contexts in that stack.

📊 Practical Example Scenario: We have a table of sales data like this:

SalespersonRegionSales
AliceEast500
BobEast700
AliceWest600
BobWest800

Now, we want to calculate a ranking of each salesperson within each region based on sales.

Step-by-Step Use of EARLIER 1. Add a calculated column: Sales Rank

DAX

Sales Rank = 
CALCULATE(
    COUNTROWS('SalesData'),
    FILTER(
        'SalesData',
        'SalesData'[Region] = EARLIER('SalesData'[Region])
        && 'SalesData'[Sales] > EARLIER('SalesData'[Sales])
    )
) + 1

How This Works: Let’s break it down:

Output:

SalespersonRegionSalesSales Rank
AliceEast5002
BobEast7001
AliceWest6002
BobWest8001

When to Use EARLIER:

✅ Use in:

🚫 Don’t use in:

Equivalent Using Variables (Modern DAX Approach)

DAX

Sales Rank = 
VAR CurrentRegion = 'SalesData'[Region]
VAR CurrentSales = 'SalesData'[Sales]

RETURN
CALCULATE(
    COUNTROWS('SalesData'),
    FILTER(
        'SalesData',
        'SalesData'[Region] = CurrentRegion
        && 'SalesData'[Sales] > CurrentSales
    )
) + 1

This version is easier to read and avoids the confusing nested row context of EARLIER().