# Using a for loop in column formula

Hello, I am trying to write a formula with the following logic:

1. check if a particular word (ie “mtd_sk”) is a selected value in the choice field named “Certs_Disa”.
2. if the above condition is true, return the field value “EffectiveDt” (a date value) in the column.

The below code is the formula I wrote, but it is not working… any thoughts?

``````for cert in \$Certs_Disa:
if cert.lower == "mtd_sk":
return \$EffectiveDt
``````

You need to call the method: `cert.lower()`

You say `Certs_Disa` is a choice field, which can only contain one value. I assume you mean choice list? If not, you shouldn’t use a loop at all, you’re actually looping over individual characters of a string.

Either way, you should know the exact value of the choice, e.g. `"Mtd_Sk"`, unless somehow you have multiple configured choices which differ only in case (which sounds dangerous), or the cell can contain invalid choices. In that case you can simplify your formula to something like `if "Mtd_Sk" in \$Certs_Disa:` depending on the correct value and assuming `\$Certs_Disa` is a choice list.

1 Like

Thank you. I understand the danger of multiple choices which differ in case… as well as the low likelyhood of mistakenly adding a value … was just being OCD.

rookie mistake of failing to call the function by ending in “()”.

Anyway, I will take your suggestion of simplifying the formula to:

``````for cert in \$Certs_Disa:
if "Mtd_Sk" in \$Certs_Disa
return \$EffectiveDt
``````

The whole formula can just be:

``````  if "Mtd_Sk" in \$Certs_Disa
return \$EffectiveDt
``````

The `in` means you don’t need a loop, since you’re not using `cert`.

1 Like

For all posterity… i left off the “:”
corrected version

`````` if "Mtd_Sk" in \$Certs_Disa:
return \$EffectiveDt
``````