Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!
what is the row context? and what is its relation with EARLIER function? (i need explanation with some examples)
Hi, @waleed111
DAX automatically creates a row context when you define a calculated column, use X-ending functions(SUMX, MAXX ...), 'ADDCOLUMNS', 'SUMMERIZE'.
When you defined the calculated column, DAX started an iteration from the first row of the table; it created a row context containing that row and evaluated the expression. Then it moved on to the second row and evaluated the expression again. A row context is a context that always contains a single row and DAX automatically defines it during the creation of calculated columns.
Actually, there are always two context: the row context and the filter context. They are the only kind of contexts in DAX. Thus, they are the only way to modify the result of a formula. Any formula will be evaluated under these two distinct contexts: the row context and the filter context.
For further information, you may refer to the link .
Best Reagrds
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Row Context - When you create a measure then it works at the grouped data level. Means calculation will happen at city wise, state wise, category wise, etc.
If I have formula sum(Table[A]) / Sum(Table[B]) , the will first sum up till that level and then divided.
Now if use a filter
if(Max(City[City]) = "Abc", [Measure1], [MeasureB]), Now from where City value will come here; one that is in the row of your visual. That is your row context. If not in a row; then selected value on-page. Else it this will get blank value.
Row context help in many calculations. time intelligence.
Color measure for conditional formatting
Color Date = if(FIRSTNONBLANK('Date'[Date],TODAY()) <today(),"lightgreen","red")
refer: https://www.sqlbi.com/articles/row-context-and-filter-context-in-dax/
Earlier - Very High level is that it provides another copy to create lookup. We have partitioned data to get value.
example
First Sales = minx(filter(Sales, Sales[Customer Id]=EARLIER(Sales[Customer Id]) ),Sales[Sales Date])
Last Sales = maxx(FILTER(Sales,[Customer Id]=EARLIER(Sales[Customer Id]) && Sales[Sales Date] >EARLIER(Sales[Sales Date])),[Sales Date])
Refer: https://www.red-gate.com/simple-talk/sql/bi/cracking-dax-the-earlier-and-rankx-functions/
Row context is only enforced when you are in a calculated column situation or you are using ADDCOLUMNS in a measure. Basically means that the row adds context to your calculation.
See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column =
VAR __Current = [Value]
VAR __Previous = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Value])
RETURN
__Current - __Previous
EARLIER is the worst named function ever. Within a column formula it basically means "value in the current row". Many people eschew EARLIER and use something like VAR __Current = [Column], either way.
| User | Count |
|---|---|
| 55 | |
| 39 | |
| 36 | |
| 21 | |
| 19 |
| User | Count |
|---|---|
| 138 | |
| 102 | |
| 59 | |
| 36 | |
| 35 |