[Solved] Summing specified records in a report

Getting your data onto paper - or the web - Discussing the reports features of Base
Locked
Nocton
Volunteer
Posts: 539
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

[Solved] Summing specified records in a report

Post by Nocton »

I have a report where I wish to count only specified records, e.g. I wish to count all records printed which have a field set to True or Yes rather than False or No. How can I do this? I have tried various functions, but can't get anything to count over the whole record set.

Regards,
Nocton
Last edited by Nocton on Tue Mar 05, 2013 10:57 am, edited 1 time in total.
OpenOffice 4.1.16 on Windows 10 & 11
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Summing specified records in a report

Post by Villeroy »

A working report engine would separate the True records from the False records and aggregate them separately.

In a Calc report this would be a matter of either 2 additional COUNTIF formulas or a pivot table with the booleans as column field.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
chrisb
Posts: 300
Joined: Mon Jun 07, 2010 4:16 pm

Re: Summing specified records in a report

Post by chrisb »

Hello Nocton

I assume your field is a text field & that you use Report Builder.

The 'ISTEXT' function does not work so if this text field contains NULL values I suggest using the COALESCE function within your query to replace them with empty strings.

Once every field contains a value it's easy to count your records.
You will need to create a User-Defined Function.
I know that you have the knowledge to do this so I will not waste time spelling it out just remember to create it in the relevant group.

Ignore the apostrophes contained in the following lines.

I have named the formula as 'Count_Yes_True'.
I have named the fieldname as 'Flag'.

FORMULA PROPERTIES:-
Name: 'Count_Yes_True'
Formula: '[Count_Yes_True]+OR([Flag]="Yes";[Flag]="True")'
Initial value: 'IF(OR([Flag]="Yes";[Flag]="True");1;0)'

An interesting fact is that when using only the 'OR' function i.e. 'OR([Flag]="Yes";[Flag]="True")' to set the 'Initial value' the formula would not reflect a TRUE initial value.
I found it necessary to enclose the 'OR' function within the 'IF' function.
open office 4.1.14 & LibreOffice 6.4.4.2 x64 using HSQL 1.8.0.10 (Embedded) and HSQL 2.6.0 (Split) on Windows 10
Nocton
Volunteer
Posts: 539
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Summing specified records in a report

Post by Nocton »

Thank you, chrisb, that works perfectly. I had a work around using a couple of queries, but this is more elegant and part of the report.

Regards, Nocton
OpenOffice 4.1.16 on Windows 10 & 11
Locked