I can easily compare strings from two columns, as in:

| hello | world | KO |
| hello | hello | OK |
| world | world | OK |
#+TBLFM: $3=if("$1" == "$2", OK, KO)

But I can't compare a column to a constant string, I think I want something like this:

| hello | OK |
| hello | OK |
| world | KO |
#+TBLFM: $2=if("$1" == "hello", OK, KO)

(I manually filled OK OK KO for this one as it does not work, it gives KO KO KO.)

Am I missing something obvious?

1 Answer 1


You can turn formula debugging on to see what's going on: C-c {. When you C-c C-c on the formula again, you will see:

Substitution history of formula
Orig:   if("$1" == "hello", OK, KO)
$xyz->  if("$1" == "hello", OK, KO)
@r$c->  if("$1" == "hello", OK, KO)
$1->    if("(hello)" == "hello", OK, KO)
Result: KO
Format: NONE
Final:  KO

so for some peculiar reason, "$1" was turned into "(hello)" with the extra parens being the reason that the equality test failed. You can try changing the constant string in your formula to "(hello)": that produces the expected results but it is hardly satisfactory.

I'm not sure whether this is long-standing behavior or a recently introduced bug. Either way, I tend to avoid the Calc if in formulas that involve strings and write the formula in Elisp, where I have explicit control over conversions:

| hello | OK |
| hello | OK |
| world | KO |
#+TBLFM: $2= '(if (string-equal $1 "hello") "OK" "KO")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.