Forum Discussion
How does earlier work correctly when table is not ordered?
- 8 years ago
Hi wilson_smyth
EARLIER returns the CurrentRow on which the calculation is performed ......Not the PreviousOne which the name literally implies
This name is slighty confusing. Some experts suggest that the name of EARLIER should be CURRENTROW. But technically EARLIER refers to EARLIER row context which becomes hidden when a new ROW context is introduced for example by an ITERATOR
- 8 years ago
You are right
CurrentRow (retrived using EARLIER) is compared with every ROW of the Table used by the ITERATOR (FILTER is the iterator here)
All ITERATORS (like FILTER, SUMX etc) typically have two arguments...One is Table Expression, second is the Expression which is evaluated for every row of the Table passed as first argument
Hi wilson_smyth
EARLIER returns the CurrentRow on which the calculation is performed ......Not the PreviousOne which the name literally implies
This name is slighty confusing. Some experts suggest that the name of EARLIER should be CURRENTROW. But technically EARLIER refers to EARLIER row context which becomes hidden when a new ROW context is introduced for example by an ITERATOR
- wilson_smyth8 years agoPost Patron
Cool, that helps, but still does not make it clear how my measure can find the most recent value based on date, if the table is not sorted based on date.
Should i think of it like an itterator that just takes the first row, gets the date and then for each row, compares the dates and if the new date is newer, it now takes that one, which it returns if it finds no newer dates?
- Zubair_Muhammad8 years agoCommunity Champion
You are right
CurrentRow (retrived using EARLIER) is compared with every ROW of the Table used by the ITERATOR (FILTER is the iterator here)
All ITERATORS (like FILTER, SUMX etc) typically have two arguments...One is Table Expression, second is the Expression which is evaluated for every row of the Table passed as first argument
- Zubair_Muhammad8 years agoCommunity Champion
Eversince the Introduction of VARIABLES in DAX........In most cases you can avoid using EARLIER by using VARIABLES instead
Following DAX should give you same results as your formula
AttendanceDate Ranking = VAR CurrentRowDate = 'Event Attendance'[Event Date].[Date] VAR CurrentRowContactID = 'Event Attendance'[Column1.ContactID] RETURN COUNTROWS ( FILTER ( 'Event Attendance', 'Event Attendance'[Event Date] >= CurrentRowDate && 'Event Attendance'[Column1.ContactID] = CurrentRowContactID ) )