In column view, it is possible to calculate both the display value of a property, and set the actual value in an entries property drawer, from any other property by setting org-columns-modify-value-for-display-function
suitably. This function is called for each value (cell) that is displayed in column view, with point at the entry whose values are to be be displayed. This means that all the entries other property values are accessible via (org-entry-get nil PROPERTY)
.
For the given example, say we have the following Org file:
:PROPERTIES:
:COLUMNS: %30ITEM %ESTIMATED %SPENT %REMAINING
:END:
* task 1
:PROPERTIES:
:ESTIMATED: 8
:SPENT: 5
:END:
* task 2
:PROPERTIES:
:ESTIMATED: 5
:SPENT: 4
:END:
After we set
(defun my-column-display-value-transformer (column-title value)
"Modifies the value to display in column view.
Calculates a value for the REMAINING column when
both the ESTIMATE and SPENT properties are non-nil."
(when (equal column-title "REMAINING")
(let ((estimated (org-entry-get nil "ESTIMATED"))
(spent (org-entry-get nil "SPENT")))
(when (and estimated spent)
(number-to-string
(- (string-to-number estimated)
(string-to-number spent)))))))
(setq org-columns-modify-value-for-display-function
#'my-column-display-value-transformer)
activating column view (M-x org-columns
) will show the values of the REMAINING column as desired, and these values will be updated when the values of in the SPENT column are changed from column view. However, no actual values get written for the REMAINING property into the entries property drawers; they are just display values.
If you really want to write the REMAINING values into the property drawers you can use this instead:
(defun my-column-display-value-transformer (column-title value)
"Modifies the value to display in column view.
Calculates a value for the REMAINING column when
both the ESTIMATE and SPENT properties are non-nil."
(when (equal column-title "REMAINING")
(let ((estimated (org-entry-get nil "ESTIMATED"))
(spent (org-entry-get nil "SPENT"))
remaining)
(when (and estimated spent)
(setq remaining (number-to-string
(- (string-to-number estimated)
(string-to-number spent))))
(org-entry-put nil "REMAINING" remaining)
remaining))))
(setq org-columns-modify-value-for-display-function
#'my-column-display-value-transformer)