<!-- https://learnsql.cpetoday.com/functions/dax/earliest -->
# EARLIEST

Language: DAX
Category: Filter and context
Syntax: EARLIEST(<column>)
Summary: Returns the value of a column from the outermost row context, the row where the nesting started.
Returns: A scalar value.
Level: Advanced
Related: EARLIER, VAR, FILTER, RELATED, CALCULATE, ADDCOLUMNS

## What it does
EARLIEST works like `EARLIER`, but it goes all the way out to the outermost row context instead of one level up. It matters only when a formula has nested row contexts, such as a `FILTER` inside another iterator. Most models never need it. With only one level of nesting, EARLIER and EARLIEST return the same value.

## Syntax and arguments
- **column**: the column whose value on the outermost row you want. There is no level number.

## Example
A calculated column on Sales counts the other lines for the same product and the same store that have a larger amount than this line. Each row in the outer loop is the sales line being calculated.

```dax
Same Product Lines Above =
COUNTROWS (
    FILTER (
        Sales,
        Sales[ProductKey] = EARLIEST ( Sales[ProductKey] )
            && Sales[StoreKey] = EARLIER ( Sales[StoreKey] )
            && Sales[SalesAmount] > EARLIER ( Sales[SalesAmount] )
    )
)
```

In this single loop, the outermost row and the calculated line are the same row, so EARLIEST and EARLIER return the same values. The example shows the syntax. The two functions differ only when a second iterator wraps the first, so check the results with a small table before you rely on either.

## Things to watch
- The difference shows only in nested iterators, two or more levels deep.
- For new work, use variables and clear filters rather than these functions.
- Mixing EARLIER and EARLIEST across levels is easy to get wrong. Test with a few rows and compare to a hand count.
- Neither function works in a measure that has no outer row context.

## In business terms
Rarely needed in finance reporting. It is useful when reviewing an older workbook or model that uses nested row logic, such as ranking lines within a store within a region, and you need to know what the formula does before you change it.
