0
0
Power BIbi_tool~5 mins

EARLIER for row context in Power BI - Step-by-Step Guide

Choose your learning style9 modes available
Introduction
EARLIER helps you compare values in the current row with values in previous rows. It solves the problem of calculating values that depend on other rows in the same table, like ranking or running totals.
When you want to calculate a rank of sales for each product compared to others in the same category.
When you need to find the previous date's sales amount for each row in a sales table.
When you want to count how many times a customer bought a product before the current purchase.
When you want to create a running total that sums values up to the current row.
When you want to compare each row's value to the maximum value in the same group.
Steps
Step 1: Open the Modeling tab
- Power BI Desktop ribbon
You see options to create new measures and columns
Step 2: Click New column
- Modeling tab
A formula bar appears to write a DAX expression for the new column
Step 3: Type a DAX formula using EARLIER
- Formula bar
The new column calculates values comparing current row to earlier rows
💡 Use EARLIER inside a FILTER function to refer to the current row's value while filtering other rows
Step 4: Press Enter
- Formula bar
The new column is added to the table and shows calculated results for each row
Step 5: Check the results in the Data view
- Data view pane
You see the new column with values that depend on other rows in the table
Before vs After
Before
Table has columns Product, Category, and Sales with raw data only
After
Table has a new calculated column showing rank of each product's sales within its category using EARLIER
Settings Reference
New column
📍 Modeling tab in Power BI Desktop
Add a column that calculates values row by row using DAX expressions
Default: No new column
Formula bar
📍 Top of Power BI Desktop when creating measures or columns
Enter DAX formulas that define calculated columns or measures
Default: Empty
Common Mistakes
Using EARLIER outside of a row context like in a measure
EARLIER only works inside calculated columns where row context exists, not in measures
Use EARLIER only in calculated columns or use other functions like variables in measures
Not wrapping EARLIER inside a FILTER function when comparing rows
EARLIER needs a filter context to compare current row value to other rows
Use EARLIER inside FILTER to create the correct row context for comparison
Summary
EARLIER lets you compare the current row to previous rows in calculated columns.
It works only in row context, typically inside FILTER functions.
Use EARLIER to solve problems like ranking, running totals, and comparisons within groups.