I am working with a data set where the equation that is done is determined by a property (ex. red flowers have a different equation than blue flowers). All of the equations use the same inputs (ex. number of petals). Since the number of properties could potentially be very large (20+), I do not want to use if statements to select my equation.
Is it possible to select the equation from a table and then use the let function to translate it into a usable equation?
I currently have it set up as: =LET(numPetals,A1,Sheet2!B3) which provides me an output as a text string (ex "numPetals*2"), which is frustrating because when I type in that text string into the LET function (instead of directing it to the cell where it is written), it provides me the correct answer. It appears as though it reads in the equation as a text string and then gives that as an answer rather than evaluating that text string as it is written.
My final goal is to be able to use the VLOOKUP with the LET function to be able to grab the correct equation based on the color. So ideally, with A1 = the number of petals (2) and B2 = the color of the flower (Red), =LET(numPetals,A1,VLOOKUP(B2,Sheet2!A3:B4,2,FALSE)) would be evaluated as =LET(numPetals,2,numPetals*2) or 4, and I could use that for all of my data. Another example would be that for a blue flower with 4 petals, the answer would be 7.
Sheet 2
| Color | Equation | 
|---|---|
| Red | numPetals*2 | 
| Blue | numPetals+3 | 
Thank you for any possible help!
With the approach in this answer:
EVAL corresponding to:
=LAMBDA(x,EVALUATE(x))
=EVAL(SUBSTITUTE(XLOOKUP(B2,Sheet2!A3:A4,Sheet2!B2:B4),"numPetals",A1))For multiple replace
=EVAL(REDUCE(XLOOKUP(B2,Sheet2!A3:A4,Sheet2!B2:B4),
{"numPetals","numLeaves"},LAMBDA(x,y,SUBSTITUTE(x,y,A1))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With