Evaluating expressions inside conditionals works in elisp
(defun usd(amount currency)
(if (string= currency "USD")
amount
(/ amount 3.75)
)
)
(usd 123 "USD") => 123
(usd 123 "SAR") => 32.8
(defun usd(amount currency)
(if (string= currency "USD")
amount
(/ amount 3.75)))
(usd 123 "USD") ; => 123
(usd 123 "SAR") ; => 32.8
But doesn't work inside an org table
| amount | currency | USD |
|--------+----------+--------|
| 123 | USD | 123 |
| 54 | USD | 54 |
| 223 | SAR | #ERROR |
| 54 | USD | 54 |
| 52 | SAR | #ERROR |
#+TBLFM: $3='(usd $1 $2)
Why would this error happen? I could solve this problem by having an intermediate column
| amount | currency | intermediate | USD |
|--------+----------+--------------+-------|
| 123 | USD | 1 | 123 |
| 54 | USD | 1 | 54 |
| 223 | SAR | 0.26667 | 59.47 |
| 54 | USD | 1 | 54 |
| 52 | SAR | 0.26667 | 13.87 |
#+TBLFM: $3='(if (string= $2 "USD") 1 .26667)::$4=round($1*$3,2)
But that makes the table unnecessarily bigger.