Forum Discussion
Choose MAX Date where it is less than or equal to another date
- Apr 09, 2022
This is just playing with dynamic array solutions. Each formula needs to be applied row by row. BYROW is the obvious solution but only accepts one array whereas MAP accepts multiple parameters but will not extract the row to search from an array.
= BYROW(dateArr, LAMBDA(keyDate, XLOOKUP("", keyDate, status,"-",-1,-1) ) ) = BYROW(firstDateArr:dateArr, LAMBDA(a, XLOOKUP(a firstDateArr, a dateArr, status,"-",-1,-1) ) )The trick in the second formula is the intersection of the original arrays with the dynamic row 'a'.
Alternatively, using MAP,
= MAP(firstDateArr,keyDatesϑ, LAMBDA(crit,datesϑ, XLOOKUP("", datesϑ(),status,"-",-1,-1) ) ) = MAP(firstDateArr,keyDatesϑ, LAMBDA(crit,datesϑ, XLOOKUP(crit, datesϑ(),status,"-",-1,-1) ) )The trick here is that the array of key dates has been passed as a thunk, so allowing MAP to work with it. In the formula, each scalar thunk is expanded to a row array by the term datesϑ().
keyDatesϑ = BYROW(dateArr,Thunkλ); Thunkλ = LAMBDA(x,LAMBDA(x))To create a two-dimension array of results is possible but lacks elegance.
This is just playing with dynamic array solutions. Each formula needs to be applied row by row. BYROW is the obvious solution but only accepts one array whereas MAP accepts multiple parameters but will not extract the row to search from an array.
= BYROW(dateArr,
LAMBDA(keyDate,
XLOOKUP("", keyDate, status,"-",-1,-1)
)
)
= BYROW(firstDateArr:dateArr,
LAMBDA(a,
XLOOKUP(a firstDateArr, a dateArr, status,"-",-1,-1)
)
)
The trick in the second formula is the intersection of the original arrays with the dynamic row 'a'.
Alternatively, using MAP,
= MAP(firstDateArr,keyDatesϑ,
LAMBDA(crit,datesϑ,
XLOOKUP("", datesϑ(),status,"-",-1,-1)
)
)
= MAP(firstDateArr,keyDatesϑ,
LAMBDA(crit,datesϑ,
XLOOKUP(crit, datesϑ(),status,"-",-1,-1)
)
)
The trick here is that the array of key dates has been passed as a thunk, so allowing MAP to work with it. In the formula, each scalar thunk is expanded to a row array by the term datesϑ().
keyDatesϑ = BYROW(dateArr,Thunkλ);
Thunkλ = LAMBDA(x,LAMBDA(x))
To create a two-dimension array of results is possible but lacks elegance.