I would like to create a table where one column contains a range of week numbers and another contains the clocked file time for each of those weeks. The latter column should be filled automatically using a table formula. Therefore, whatever functions the table formula requires should be side-effect-free (i.e. not mess with my buffer, only return the clocked time). I've looked at a few org-clock-* functions but my Emacs-Lisp is not impressive and I can't seem to be able to find a sane way to do this.

In the following example I added the file times manually. What I'm asking for is a table formula in Emacs-Lisp that computes the column File Time automatically.

* Work
CLOCK: [2024-01-01 Mon 09:00]--[2024-01-01 Mon 17:30] =>  8:30
CLOCK: [2024-01-08 Mon 09:00]--[2024-01-08 Mon 16:30] =>  7:30
CLOCK: [2024-01-09 Tue 09:00]--[2024-01-09 Tue 17:00] =>  8:00
CLOCK: [2024-01-22 Mon 09:00]--[2024-01-22 Mon 16:00] =>  7:00

* Time Sheet

| Calendar Week | File Time |
|             1 |     08:30 |
|             2 |     15:30 |
|             3 |     00:00 |
|             4 |     07:00 |
#+TBLFM: $1=@# - 1
  • I will probably need much more information before I can even begin answering this question. Are you talking about a single file or multiple files (perhaps all your agenda files? Do you want the total for all files in the latter case or split up per file? What should happen if there is an open clock? and probably more niggly details once you get started.
    – NickD
    Commented Apr 29 at 16:28
  • This forum is probably ill-suited for the back-and-forth required, so I would recommend that you post your question (with as many additional details as you can muster) to the Org mode mailing list - as a mailing list, it is much better suited to longer discussions.
    – NickD
    Commented Apr 29 at 16:28
  • 1
    @NickD I'm sorry if I made it seem complicated. What I'm asking for is actually very simple. I need a function that takes a calender week number (if it takes a format like 2024-W50 that's fine as well) and returns the file time for the current buffer—just like org-clock-display but non-interactive and taking a week number as an argument.
    – Wildebeest
    Commented Apr 29 at 18:55
  • 1
    Yes, I tend to complicate things :-) The example helps. Good job!
    – NickD
    Commented Apr 29 at 21:32

1 Answer 1


I did it! Close enough at least. First, install this function:

(defun my/org-clock-sum-week (iso-week)
  (let* ((r (org-clock-special-range iso-week))
         (start (car r))
         (end (cadr r)))
    (org-duration-from-minutes (org-clock-sum start end))))

Then you can use the table formulas below this table:

| Calendar Week | File Time |
| 2024-W1       |      8:30 |
| 2024-W2       |     15:30 |
| 2024-W3       |      0:00 |
| 2024-W4       |      7:00 |
#+TBLFM: $1='(format "2024-W%d" (1- @#))::$2='(my/org-clock-sum-week $1)
  • This works fine, I think. How did you find out that "2024-W2" is a reasonable argument for org-clock-special-range? I'm asking because I did C-h f org-clock-special-range and I found the doc string confusing. I checked the code and I now understand the function a bit better, but the doc string now seems woefully incomplete. If you agree, would you be willing to submit a patch for that? M-x org-submit-bug-report would do for a bug report, but ideally you could attach a patch to the report.
    – NickD
    Commented Apr 30 at 8:42
  • 1
    @NickD I agree that the doc string for this function is confusing and incomplete. I figured it out by reading the definitions in org-clock.el for functions that seemed promising. TBH, I don't even understand what org-clock-special-range returns, I just saw how it was used along with org-clock-sum in the body of org-clock-sum-custom (or which the doc string is incorrect as well, BTW). I fear submitting a patch is still outside of my circle of competence.
    – Wildebeest
    Commented May 1 at 6:39
  • 1
    OK, I might take a crack at it after I figure out all the wrinkles. Thanks!
    – NickD
    Commented May 1 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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