When generating a clock-table in org-mode, is it possible to have the table generated in reverse-chronological order? For example,

#+BEGIN: clocktable :maxlevel 3 :tstart "<-1w>" :tend "<now>" :step day :fileskip0 :formatter :link t :hidefiles f :narrow 100

will result in something like the following:

Daily report: [2021-01-04 Mon]
| Headline     | Time   |
| *Total time* | *0:00* |

Daily report: [2021-01-05 Tue]
| Headline                                          | Time   |
| *Total time*                                      | *0:03* |
| task 1                                            | 0:03   |

Daily report: [2021-01-06 Wed]
| Headline                                                           |   Time |
| *Total time*                                                       | *3:39* |
| another task                                                       | *3:39* |


How can this be made to generate a table such that the top entry is the most recent day instead of the oldest day?

  • 1
    One way to increase the chances of a satisfactory answer is to include the Org mode file tha you used to generate the table. That way, somebody can cut and paste the file and try it out, without having to start from scratch - you'd be amazed what a difference that would make in the willingness of people to help :-)
    – NickD
    Jan 12 at 11:30

The doc says:


A cons cell containing the column to sort and a sorting type
E.g., ‘:sort (1 . ?a)’ sorts the first column alphabetically.

The sorting is done by org-table-sort-lines and doing C-h f org-table-sort-lines gives this:

If SORTING-TYPE is specified when this function is called from a Lisp program, no prompting will take place. SORTING-TYPE must be a character, any of (?a ?A ?n ?N ?t ?T ?f ?F) where the capital letters indicate that sorting should be done in reverse order.

So I would try adding

:sort (2 . ?T)

to the clocktable line. Untested and I'm not sure it works across tables: it might only work within a table.

EDIT: This indeed affects each day's table separately from all the other tables - it does not affect the order of the tables. That order is hard-wired in the function org-clocktable-steps in the file org-clock.el and, AFAICT, cannot be changed without modifying that function.

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.