How can I make checklist counters accumulate results from subheaders in org-mode?

I want to do something like this in Emacs' Org-mode:

* headline [%]
** subheadline1 [%]
   - [ ] list item 1
   - [ ] list item 2
** subheadline2 [%]
   - [ ] list item 1
   - [ ] list item 2

The purpose here is to have the percentage cookie at headline present the total percentage of completed tasks computed from the percentage cookies of its subheadlines.

If "subheadline1" is at 40%, and "subheadline2" is at 50%, then "headline" should be at (40 + 50) / 2 = 45 % (2 is the number of subheadlines).

Is it possible? If so, how?


Solution 1:

I don't think that is entirely possible at the moment. Checkboxes deal with their children only by default as a complete/incomplete cookie. (See Checkboxes). However there is the option to use org-checkbox-hierarchical-statistics and include all checkboxes in the headline, not just direct children.

So by adding or evaluating

(setq org-checkbox-hierarchical-statistics nil)

You can set this feature (count all checkboxes in tree, recursively) for all org-files.

If you want to set it for specific trees only, the docstring provides the answer:

org-checkbox-hierarchical-statistics is a variable defined in `org-list.el'.
Its value is t

Documentation:
Non-nil means checkbox statistics counts only the state of direct children.
When nil, all boxes below the cookie are counted.
This can be set to nil on a per-node basis using a COOKIE_DATA property
with the word "recursive" in the value.

In this case your example would become:

* headline [%]
:PROPERTIES:
:COOKIE_DATA: recursive
:END:
** subheadline1 [%]
   - [ ] list item 1
   - [ ] list item 2
** subheadline2 [%]
   - [ ] list item 1
   - [ ] list item 2

To use your further example:
Subheadline 1 = 2/4 = 50%
Subheadline 2 = 2/5 = 45%
Headline 1 = 4/9 = 44.44%