Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
waleed111
Helper V
Helper V

Row context

what is the row context? and what is its relation with EARLIER function? (i need explanation with some examples)

3 REPLIES 3
v-alq-msft
Community Support
Community Support

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.

amitchandak
Super User
Super User

@waleed111 ,

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/

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Community Champion
Community Champion

@waleed111 

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. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.