Auto compute column based on enumlist column selection in form

In my form, I would like to auto compute the ‘food’ column values based on the ‘nutrition’ selection (enumlist). So if, ‘fruit’ is selected, then ‘food’ should have value ‘apple’. If both ‘fruit’ and ‘dairy’ are selected then ‘food’ value should be ‘apple, milk’

I have the idea that there should be an ‘If’ statement in the auto compute column for ‘food’, but my syntax is horrible:

Something like:
AND(IF([Nutrition]=CONTAINS("fruit")) then "apple",IF([Nutrition]=CONTAINS("dairy")) then "milk")

The expression shall be like this:

IFS(
    AND(
        CONTAINS([Nutrition],"fruit"),
        NOT(CONTAINS([Nutrition],"dairy")
    ),{"apple"},
    AND(
        CONTAINS([Nutrition],"fruit"),
        CONTAINS([Nutrition],"dairy")
    ),{"apple", "milk"}
)

But what value you will expect if only “dairy” is chosen from the ENUMLIST?

1 Like

IN(), not CONTAINS().

2 Likes

I’ve got this that works but seems klunky.
IFS( AND( NOT(CONTAINS([Nutrition],"fruit")), (CONTAINS([Nutrition],"dairy")) ), "milk", AND( NOT(CONTAINS([Nutrition],"dairy")), (CONTAINS([Nutrition],"fruit")) ), "apple", AND( (CONTAINS([Nutrition],"fruit")), (CONTAINS([Nutrition],"dairy")) ), "apple, milk" )

I tried with IN() but it doesn’t pull up the correct values when both ‘fruit’ and ‘dairy’ are selected.
IFS( IN("apple, milk",[Nutrition]), "fruit, dairy", IN("apple",[Nutrition]), "fruit", IN("milk",[Nutrition]), "dairy", )

Try:

(
  LIST()
  + IFS(IN("dairy", [nutrition]), {"milk"})
  + IFS(IN("fruit", [nutrition]), {"apple"})
)

1 Like

Steve:

+ IFS

That works! Thanks First time I’ve seen code with a plus sign. Don’t think I’ve ever seen documentation on it.

1 Like

@Tom_automated
Might worth reading

1 Like