[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Formulas on table cells containing '$'
From: |
Bruno Barbier |
Subject: |
Re: Formulas on table cells containing '$' |
Date: |
Thu, 18 May 2023 20:55:17 +0200 |
Jeff Trull <edaskel@att.net> writes:
> While investigating an error executing a table formula I discovered that
> cells containing '$' cause column references to be executed even when no
> attempt is made to evaluate cell contents as code. Here's a simple example:
>
Confirmed.
org tries first to resolve all references, recursively.
'(length '(@1$3..@I$3))
{ resolving @1$3..@I$3 into ("$200.00" "$1.13" "$301.22") }
= '(length '("$200.00" "$1.13" "$301.22"))
{ resolving $200 into ...
ERROR: '$200' is an invalid reference.
It's probably not by designed, but, it's definitely a limitation of
the current implementation.
As a workaround, you could hide your reference in elisp and resolve it
manually using `org-table-get-range'. That way you can add/remove "$" as
needed.
For example:
| 3/1/2023 | Deposit | $200.00 |
| 3/13/2023 | Interest | $1.13 |
| 4/1/2023 | Deposit | $301.22 |
|-----------+------------------------+---------|
| | Number of Transactions | 3 |
| | Total | $502.35 |
#+TBLFM: @4$3='(length (org-table-get-range (concat "@" "1$" "3..@" "I$"
"3")))
#+TBLFM: @5$3='(format "$%.2f" (apply '+ (mapcar (lambda (x)
(string-to-number (substring x 1))) (org-table-get-range (concat "@" "1$"
"3..@" "I$" "3")))))
Bruno