5

I plan & track my holidays in an Org mode file. In it I use Column View to get a quick overview of what I've planned so far, so that I know how many days I've got left. I use this column setup:

#+COLUMNS: %TIMESTAMP(When) %ITEM(What) %Confirmed(Confirmed?){X/} %Days{+}
#+Confirmed_ALL: "[ ]" "[X]"

It shows a table something like this:

| When                               | What                          | Confirmed? | Days |
|------------------------------------+-------------------------------+------------+------|
|                                    | * Holiday                     | [2/3]      |   14 |
| <2017-02-20 Mon>--<2017-03-01 Wed> | ** Picking fights with bears  | [X]        |    8 |
| <2017-05-04 Thu>--<2017-05-09 Tue> | ** Give bear-fighting lessons | [X]        |    3 |
| <2017-05-10 Wed>--<2017-05-12 Fri> | ** Lick wounds                | [ ]        |    3 |

Is there a way to make the {+} only add up the days that are confirmed? I'd like to make the table look something like this:

| When                               | What                          | Confirmed? | Confirmed Days | Days |
|------------------------------------+-------------------------------+------------+----------------+------|
|                                    | * Holiday                     | [2/3]      |             11 |   14 |
| <2017-02-20 Mon>--<2017-03-01 Wed> | ** Picking fights with bears  | [X]        |              8 |    8 |
| <2017-05-04 Thu>--<2017-05-09 Tue> | ** Give bear-fighting lessons | [X]        |              3 |    3 |
| <2017-05-10 Wed>--<2017-05-12 Fri> | ** Lick wounds                | [ ]        |                |    3 |

Any help appreciated!

3

I ended up adding the ability to do this as a feature to Org mode. It is available in Org 9.2 (and perhaps earlier). It's a bit too obscure to be documented in the manual, but essentially org-columns-summary-types entries can take an optional COLLECT function now.

You can use this to make collection of a property from an entry conditional on another entry. E.g. given this configuration:

(defun custom/org-collect-confirmed (property)
  "Return `PROPERTY' for `CONFIRMED' entries"
  (let ((prop (org-entry-get nil property))
    (confirmed (org-entry-get nil "CONFIRMED")))
    (if (and prop (string= "[X]" confirmed))
    prop
      "0")))

(setq org-columns-summary-types
      '(("X+" org-columns--summary-sum
     custom/org-collect-confirmed)))

You can have a file bananas.org containing:

#+columns: %ITEM %CONFIRMED %Bananas{+} %Bananas(Confirmed Bananas){X+}

* All shipments
** Shipment 1
   :PROPERTIES:
   :CONFIRMED: [X]
   :Bananas:  4
   :END:

** Shipment 2
   :PROPERTIES:
   :CONFIRMED: [ ]
   :BANANAS:  7
   :END:

… and when going to the top of that file and entering column view you should expect to see something like:

| ITEM          | CONFIRMED | Bananas | Confirmed Bananas |
|---------------+-----------+---------+-------------------|
| All shipments |           |      11 |                 4 |
| Shipment 1    | [X]       |       4 |                 4 |
| Shipment 2    | [ ]       |       7 |                 7 |

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.