Suppose our cursor/point it located on the first line of Parent Task in the following:

* Parent Task

** Sub-Task A

** Sub-Task B

Question: Is there a way to write a function which (i) sums the :TALLY sub-properties from Sub-Task A and Sub-Task B and (ii) inserts them into the :TALLY_SUM property of Parent Task?

I know that for part (ii) we can use the org-mode property API function (org-entry-put "TALLY_SUM" <sum>).

1 Answer 1


The following function should do the job:

(defun org-sum-tally-in-subtree ()
  "Add up all the TALLY properties of headings underneath the current one
The total is written to the TALLY_SUM property of this heading"
  (org-entry-put (point) "TALLY_SUM"
                  (let ((total 0))
                       (lambda ()
                         (let ((n (org-entry-get (point) "TALLY")))
                           (when (stringp n)
                             (setq total (+ total (string-to-number n))))))))

Two points to note:

  1. All sub-headings below the current point are searched, not just the next level down
  2. The code does not enforce that TALLY should be an integer, so it also works for float values


** Parent Task
:TALLY_SUM: 22.201

Do =M-x org-sum-tally-in-subtree= here

*** Sub-Task A

**** Sub-sub task
:TALLY:    10.001

*** Sub-Task B
:TALLY: 8.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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