How to combine queries

Do you want to combine the daily totals list with a sum at the end for the weekly average? In this case you need to do something like shown in the post below:

If you want to make another table just showing the weekly average, this is the way to transform your queries. First you need to move any calculated fields from the TABLE definition into a FLATTEN statement after the GROUP BY.

TABLE sum(rows.workTime) as dailyTotal
WHERE file.folder = this.file.folder
GROUP BY file.link as Day

Changes into

TABLE <to be decided>
WHERE file.folder = this.file.folder (+ plus the other stuff)
GROUP BY file.link as Day
FLATTEN sum(rows.workTime) as dailyTotal

And now we can do another GROUP BY and introduce the new values we want to display.

TABLE WITHOUT ID average(rows.dailyTotal) as "Weekly average"
WHERE file.folder = this.file.folder (+ plus the other stuff)
GROUP BY file.link as Day
FLATTEN sum(rows.workTime) as dailyTotal
GROUP BY true

Hopefully that make sense, and please note that you do need to keep the other stuff in between the first WHERE and GROUP BY as you had originally. I’ve left it out of the examples to clarify which steps needs to be taken to transform your query.