transaction.scm date subtotal options - calling wizards ...

Christopher Lam christopher.lck at
Fri Sep 22 11:33:45 EDT 2017

Hi John,

The origin of this project comes from my wish to produce report.
Source account=Asset:Bank. Prime-sortkey=date (subtotal quarterly) and sec-sortkey=other-accname (subtotal=true).

 01/01/16 – Allmart $200
 01/02/16 – Qmart $300
 01/03/16 – Nomart $300
 Subtotal Expense:Groceries $800
 15/01/16 – Coral $300
 15/02/16 – BQ $250
 Subtotal Expense:Petrol $550
 Subtotal 2016Q1 = $1350

However the current query mechanism means that the dates will be split up, because they’

Sent from Mail for Windows 10

From: John Ralls
Sent: Friday, 22 September 2017 10:40 PM
To: Christopher Lam
Cc: gnucash-devel at
Subject: Re: transaction.scm date subtotal options - calling wizards ...

On Sep 22, 2017, at 5:48 AM, Christopher Lam <christopher.lck at> wrote:

Hi devs,

While working on transaction.scm (again) to fix a sorting/grouping bug[1],
I came across some inconsistencies:

1. if I choose sortkey "date" "exact-time" -- they do the exact same thing,
but otherwise work well

2. if I choose sortkey "reconciled date" -- it does what it says, however
*the date-subtotal selector is not used at all.*

3. if I choose sortkey "register order"
(a) first, I'm not entirely sure what exactly this mean - *does it mean,
sort by EntryDate *(accessible by xaccTransGetDateEntered

(b) second, it allows date-subtotal selection, which to me is puzzling, but
could be acceptable if we're sorting by EntryDate

My conclusion from above would be that the original date-sorting-types has
a typo, it was (define date-sorting-types (list 'date 'exact-time
'register-order)) but it should really be (define date-sorting-types (list
'date 'exact-time 'reconciled-date))

*What would be the consensus from wizards if we had to do it right?*

I suggest:
1. We change (define date-sorting-types (list 'date 'exact-time
2. When sorting by register-order, it should disallow date-subtotals

My solution to produce my report correctly requires a custom sorting
algorithm which is nearly complete, and would override the
qof-query-set-sort-order. Work-in-progress at

[1] this bug relates to my preferred sorting/grouping: prime-sortkey=date,
subtotal=quarterly, sec-sortkey=account-name, subtotal=true. This will
produce an incorrect grouping whereby a quarter (eg 2016 Q1) will be split
incorrectly, because the query will sort by dates rather than quarters.
Documented in my comment on


I would expect “Register Order” to mean the normal sorting order of transactions in the register:
date-posted, num, date-entered, description, though it’s possible that it would look at the Sort By… settings on the source register.

“Date” should be “date-posted” for clarity. While a sort of date-entered might be amusing it’s not particularly useful. Exact time on date-posted isn’t meaningful: All transactions are posted at 10:59Z so that the date remains the same in most time zones. Similarly I’d expect that most date-reconciled entries will be grouped on a single date and time since it’s unusual to reconcile an account more than once per day (or even once per month for most people).

I don’t understand your analysis that "a quarter (eg 2016 Q1) will be split incorrectly, because the query will sort by dates rather than quarters”. Sorting by quarters is just a large-granularity sort by date; a sort by date at day granularity should be easily divided by quarters.

John Ralls

More information about the gnucash-devel mailing list