title: Timetable grouped by tag
body: <p>I'm looking for a way to use time tracking information from org-mode agenda files to build a timetable. Time spent in different tasks would be indicated, grouped by tag and restricted to a given time-frame, sort of like a clocktable dynamic block, but grouped by tag instead of file/category/headline.</p>
  
  <p>For example, if my agenda contained the following data (possibly scattered among different files):</p>
  
  <pre><code>* TODO project 1
  ** TODO task 1                                                  :tag1:
     :LOGBOOK:
     CLOCK: [2013-06-27 Thu 18:00]--[2013-06-27 Thu 19:04] =&gt;  1:04
     CLOCK: [2013-06-26 Wed 17:00]--[2013-06-26 Wed 17:32] =&gt;  0:32
     :END:
  ** TODO task 2                                                  :tag2:
     :LOGBOOK:
     CLOCK: [2013-06-27 Thu 17:00]--[2013-06-27 Thu 18:00] =&gt;  1:00
     CLOCK: [2013-06-27 Thu 15:00]--[2013-06-27 Thu 15:50] =&gt;  0:50
     :END:
  
  * TODO project 2                                                :tag2:
    :LOGBOOK:
    CLOCK: [2013-06-27 Thu 19:04]--[2013-06-27 Thu 21:00] =&gt;  1:56
    CLOCK: [2013-06-27 Thu 15:50]--[2013-06-27 Thu 17:00] =&gt;  1:10
    :END:
  </code></pre>
  
  <p>I would like to get this kind of results:</p>
  
  <pre><code>#+BEGIN: clocktable-by-tag :maxlevel 2 :tags ("p1" "p2") :tstart "2013-06-27" :tend "2013-06-28"
  | Tag  | Headline        | Time   |      |
  |------+-----------------+--------+------|
  | tag1 | *Tag time*      | *1:04* |      |
  |      | TODO project 1  | 1:04   |      |
  |      | \__ TODO task 1 |        | 1:04 |
  |------+-----------------+--------+------|
  | tag2 | *Tag time*      | *4:56* |      |
  |      | TODO project 1  | 1:50   |      |
  |      | \__ TODO task 2 |        | 1:50 |
  |      | TODO project 2  | 3:06   |      |
  #+END:
  </code></pre>
  
  <p>Is there any standard way to do this with org? If not, I'm thinking of cycling through agenda files and tags, using <code>org-get-table-data</code> to collect clocking information; would there be another, more efficient way of doing things?</p>