[GNC] filtering in report

Geoff cleanoutmyshed at gmail.com
Sun Feb 6 20:57:40 EST 2022


Hi Andy

I believe you are referring to what in English is called the 
'Transaction Report'?

In the Help Manual:
https://www.gnucash.org/viewdoc.phtml?rev=4&lang=C&doc=help

Section 9.3.1.3.1 Report Options says:

''Account Name Filter will include only selected accounts containing the 
substring. Alternatively, if the next option is checked, the account 
name filter will be matched according to full POSIX regular expressions.''

As I understand it, 'full POSIX regular expressions' do not let you 
negate a whole word, but you can negate particular characters:

https://www.ibm.com/docs/en/watson-explorer/11.0.1?topic=queries-posix-regular-expression-syntax-examples

Which leads us to a possible hacky workaround for your scenario - this 
regular expression will do the job - see attached screenshot for proof:

^.+:.+:.+:[^GR]

For those not familiar with the arcane art of regular expressions, let's 
break this down.  Remember that my chart of accounts is slightly 
different to yours, and I have a colon ':' as a delimiter, not a full 
stop '.'  Thus my accounts are:

Expenses:Farm:RedCar:Gas,
Expenses:Farm:Tractor1:Repairs,
etc.

(1) ^.+:
 From the start (^) match any character (.) one or more times (+) up to 
a colon.  This will match 'Expenses:'.

(2) .+:
Then match any character (.) one or more times (+) up to a colon.  This 
will match 'Farm:'.

(3) .+:
Then match any character (.) one or more times (+) up to a colon.  This 
will match 'RedCar:' and 'Tractor1:'.

(4) [^GR]
Then match any single character ([]) EXCEPT FOR (^) the letters 'G' or 
'R'.  This excludes the 'Gas' and 'Repairs' accounts, leaving all 
accounts that don't start with those two letters.

To adapt this for your chart of accounts you need to remember (a) that a 
full stop in a regular expression means 'match any character', and to 
match just a full stop you need to 'escape' it with a backslash '\' ; 
and (b) that regular expressions are case sensitive.  Therefore this 
expression should (I hope) work for you:

farm\..+\.[^gr]

or failing, try this:

farm\.[^.]+\.[^gr]


I said that this was a 'hacky' workaround, but given 26 upper case 
letters [A-Z] and 26 lower case letters [a-z] plus 10 digits [0-9] a 
careful, if slightly clunky, account naming convention could deliver you 
a workable and very flexible solution with up to 62 distinct child accounts.

I hope this all makes sense ;--)

In passing I also note that there *is* an option to negate the 
Transaction Filter - but this probably doesn't suit your needs.

Regards

Geoff
=====



On 6/02/2022 5:27 pm, Andreas Hentze wrote:
> Hello,
> 
> I'm struggling in a report. I hav a lot of expense and earning accounts.
> In the "Buchungsbericht" is a tab named "Filter".
> Lets have for example this accounts:
> 
> ...farm.redcar.gas
> ...farm.redcar.repair
> ...farm.redcar.insurance
> ...farm.tractor1.gas
> ...farm.tractor1.repair
> ...farm.tractor1.insurance
> 
> using as regular expression filtering with "(gas|repair)" is working fine.
> 
> But how is it possible to get the complement. i.e. all expense and
> earning accounts NOT have gas and repair in the account name?
> "NOT (gas|repair)" and "!(gas|repair)" dos not work.
> 
> How shall the regEx be formulated?
> 
> And: It would be very helpful, if the filtering does not filter only the
> name, but the description too! Then it would be easy to manage tags for
> the accounts.
> 
> And 2: It would be very helpful, to have this filter tab in the profit
> and loss report too.
> 
> best ragrds
> Andy
> _______________________________________________
> gnucash-user mailing list
> gnucash-user at gnucash.org
> To update your subscription preferences or to unsubscribe:
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> If you are using Nabble or Gmane, please see 
> https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
> -----
> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnc_account_filter.jpg
Type: image/jpeg
Size: 261856 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-user/attachments/20220207/e827eef8/attachment-0001.jpg>


More information about the gnucash-user mailing list