Skip to content

Show totals per month

A report with group_by: shows one row per group instead of one row per record. This guide builds the page “Hours per consultant and month” of a time-tracking application, and then a second page for managers. It uses the example application in dsl/examples/time-tracking.

The guide assumes a time_entries table with these columns:

  • work_date, a date
  • employee, a ref to employees
  • project, a ref to projects
  • minutes, an int
  • billable, a bool
  1. Add a page with a report of time_entries.
  2. Write group_by: with the keys. employee is a column. month(work_date) cuts the date column into months.
  3. Add one column line. A report that is grouped needs at least one. count shows the number of entries in each group.
page month_by_consultant "Hours per consultant and month" {
route: /months/consultants
access: see_time
report of time_entries "Hours per consultant and month" {
group_by: employee, month(work_date)
column entries count "Entries"
}
}

The report shows one row for each consultant and month that has at least one entry. The first column is the consultant, the second is the month, and the third is the count. The month column is headed “Month”, not “Date”. A bucket takes the name of its bucket, in the application’s language, unless you write a caption after the key (month(work_date) "Billing month").

The month is the first day of the month. It sorts in time order, and the page writes it as “September 2026”. The bucket functions are day, week, month and year. A week is an ISO week that starts on Monday.

A grouping key must be a stored column of the report’s own table. group_by: employee.department is refused. Displaying employee.department beside an employee key still makes one group per employee, rather than one group per department.

For totals by the department at filing time, store a department ref(departments) on each claim. Fill it from the employee’s page data row on create, as shown in Fill in a value the user never types. Then write group_by: department, month(claimed_on) on the claims report.

This is a historical snapshot: moving an employee to another department does not move old claims between groups. Related-path keys for the employee’s current department are not supported.

  1. Add a sum line for the minutes. A sum needs empty:. Write empty: zero to show 0 for a group that has no matching row.
  2. Add a second sum line with where: billable, for the billable minutes only.
  3. Add a computed line, decimal(2), with a value: over the lines above it. ratio divides and round sets the places.
report of time_entries "Hours per consultant and month" {
group_by: employee, month(work_date)
column entries count "Entries"
column minutes_total sum(minutes) "Minutes" {
empty: zero
}
column minutes_billable sum(minutes) "Billable minutes" {
where: billable
empty: zero
}
column hours_total decimal(2) "Hours" {
value: round(ratio(minutes_total, 60), scale: 2, ties: up)
}
}

Do not name a line like a column of the table. The table has an hours column, so the line is hours_total. The compiler refuses the name hours and suggests a name. columns:, sort: and total: name keys and lines, and filter: and search: name columns of the table. One word must not mean both.

Choose the columns, the order and the totals row

Section titled “Choose the columns, the order and the totals row”
  1. Write columns: to show the keys and lines you want, in order. Without it, the report shows every key and then every line. A line that is only a step, such as minutes_total, can stay out of columns:.
  2. Write sort: with the newest month first. The report adds the keys to the end of the sort, so the order is always complete.
  3. Write total: with the lines that the totals row shows.
report of time_entries "Hours per consultant and month" {
group_by: employee, month(work_date)
column entries count "Entries"
column minutes_total sum(minutes) "Minutes" {
empty: zero
}
column hours_total decimal(2) "Hours" {
value: round(ratio(minutes_total, 60), scale: 2, ties: up)
}
columns: employee, month(work_date), hours_total, entries
sort: month(work_date) desc, employee
total: minutes_total, hours_total, entries
empty: "No time logged."
}

The totals row is the last row of the table. It adds up all the groups, not only the groups on the current page. A computed line totals with its own value: over the totals of the lines it reads. The total hours are therefore the total minutes divided by 60 and rounded once. They are not the sum of the rounded hours above, and the two can differ in the last place.

The report shows 25 groups on a page. Write page_size: to change the number.

Write filter: with columns of the table. The filters choose the rows that are added up, before the rows are grouped.

report of time_entries "Hours per consultant and month" {
group_by: employee, month(work_date)
column entries count "Entries"
filter: work_date, project, billable
}

A reader who picks a project sees the hours of that project for each month. The totals row follows the filter. filter: and search: cannot name a line. To see the largest groups, click the header of the line to sort by it.

Write export:. The file has the same groups as the page, in the same order, and the totals row last.

report of time_entries "Hours per consultant and month" {
group_by: employee, month(work_date)
column entries count "Entries"
export: csv, xlsx
}

The file contains every group, not only the groups on one page. In the workbook, the month is a date cell and the hours keep two decimal places. In the CSV file, the month is the first day of the month. export: ics is a compile error, because a group has no date of its own. See Export a listing for the dialect and the file name.

A row filter of a right decides which rows a role reads. The example defines see_time: a consultant reads their own entries, a manager reads their own and those of their direct reports, and backoffice reads all of them.

right see_time of time_entries "See time entries" {
consultant where employee = :user.employee_id
manager where employee = :user.employee_id or employee.manager = :user.employee_id
backoffice
}

A grouped report adds up only the rows that the reader may read. The engine applies the row filter in the WHERE of the statement, before it groups the rows. A consultant who opens “Hours per consultant and month” sees their own hours. A manager sees the team’s. Backoffice sees everybody’s. One region serves all three.

A page can name roles while its region names the right. The page’s rule says who can open the page. The region’s access: narrows the rows. Both row filters apply to the same statement.

page month_by_project "Hours per project and month" {
route: /months/projects
access: manager, backoffice
report of time_entries "Hours per project and month" {
access: see_time
group_by: project, month(work_date)
column entries count "Entries"
column minutes_total sum(minutes) "Minutes" {
empty: zero
}
column hours_total decimal(2) "Hours" {
value: round(ratio(minutes_total, 60), scale: 2, ties: up)
}
columns: project, project.customer, month(work_date), hours_total, entries
sort: month(work_date) desc, project
total: minutes_total, hours_total, entries
export: csv, xlsx
}
}

Only managers and backoffice can open this page. A manager’s totals are the team’s hours, never the company’s. project.customer shows the customer of each project, because project is a ref key. A consultant who opens the address gets a 403 page.

With the demo data of the example, the manager’s totals row shows 255 entries and 716.00 hours. The totals row of backoffice shows 425 entries and 1192.00 hours. The consultant’s row shows 85 entries and 236.00 hours. Each total equals the sum of the rows in that person’s own time list. The data is a fixed snapshot in seed/ of the example, from 2026-07-22 to 2026-09-30, so your counts are the same on every day. See Load demo data and bind logins to records for the command that installs it.

  • A report has at most 3 keys and 12 lines.
  • A key is a ref, enum, bool or date column, or a bucket of a date column. A text column, a number and a datetime are not keys.
  • A group cannot link to a row page. row -> and row_action are compile errors on a grouped report. button -> <page> works.
  • There is no HAVING: filter: and search: cannot name a line.
  • A key or a line that reads a sensitive column compiles only when every role that reads the region has the grant.

The compiler names the line and the repair for each refusal. See Grouped report for every rule, and Project status for what grouped reports cannot do yet.

Website privacy policy