Forum Discussion
Formulas
- Apr 13, 2022
I don't think it is a case of a 'correct' answer. There are many variations that will work and it also depends upon the version of Excel that you use. Using modern functions but stopping short of Lambda functions one might have
= XLOOKUP( Destination,PriceTbl[Destination], SWITCH(Class, "First",PriceTbl[First], "Economy",PriceTbl[Economy]) )
I don't think it is a case of a 'correct' answer. There are many variations that will work and it also depends upon the version of Excel that you use. Using modern functions but stopping short of Lambda functions one might have
= XLOOKUP(
Destination,PriceTbl[Destination],
SWITCH(Class,
"First",PriceTbl[First],
"Economy",PriceTbl[Economy])
)- PeterBartholomew1Apr 13, 2022Silver ContributorINDEX/MATCH should work fine on legacy Excel. You could also use a second MATCH to replace the SWITCH function by a column index to use within the INDEX.
- CFrench11Apr 14, 2022Copper Contributor
On a side note I was playing around with substituting xlookup with match/index like you said. I got this reference error, as well as value error. Any idea how to fix that or what I did wrong?
- PeterBartholomew1Apr 14, 2022Silver Contributor
I write for newer versions of Excel. Perhaps this will work.
= INDEX( SWITCH([@Class], "First class", Price[First class], "Economy",Price[Economy]), MATCH([@Destination], Price[Destination], 0) )Even SWITCH requires 2016 (I think). I like it because my objective is to make the code as readable as possible. Other developers aim at as fast as possible to write or as concise as possible. Normal users do not regard their formulas as code.
- CFrench11Apr 14, 2022Copper ContributorThank You!
- HansVogelaarApr 13, 2022MVP
XLOOKUP is available to 'ordinary' users of Microsoft 365 and Office 2021, but not to users of older versions, and perhaps not to users of Microsoft 365 with delayed updates.