Simplicty and flexibility!


Function::Internal

Sum Of
sum of RELATIONSHIP column
sum of TABLENAME column

Syntax:
sum of TABLENAME|RELATIONSHIP
[ named "UNIQUE RELATIONSHIP NAME" ]
[ with {selection criteria} ]
FIELDNAME


The sum of operator sum the FIELDNAME across all records in a related table match the specified selection criteria. The result can appear as a list item in the detail area of a report or as a statistic in the summary area at the end of a report.

There's an important difference between the conditional statistical operator sum and the relational statistical operator sum of. sum sums up the FIELDNAME  of records that satisfy a specified condition among the records being processed. sum of sums the FIELDNAME queried  of matching records related to the records being processed by the script.


Parameters


TABLENAME

You can use Count of directly on a table without a predefined Relationship. Just remember that if there is a Relationship defined that doesn't have an alternative relationship name, this relationship will be named the same and the table and be used. 

RELATIONSHIP

If you use a relationship (alternative name) then the count of will be automatically restricted by the relational restriction. Read under TABLENAME for functionality when using Relationships without alternative relational name.

NAMED "Unique Relationship Name"
You can define an ad hoc named relationship directly in the Count Of function. If you do this you will possibly achieve two things. 1) You will insure against DataEase using a pre-defined relationship with the same name as the table. 2) You can re-use it again in the same script i.e. on a Sum Of etc.
WITH {selection criteria}
With the WITH statement you define the relational restriction of the function. Ex. MyCustomerNR=CustomerNR and MyDate>current date.
FIELDNAME
Name of the Data Column/Field that is being summed up ex. InvoiceLineSum, NumberComplaints, InvoiceTotal

Returns/Result


Numeric Value
The sum of FIELDNAME that fit the relational restriction. If no Relational restriction the sum of FIELDNAME in the entire table.

Examples


Example 1

In a field derivation.Simplest type. We have two tables. ThisTable and MyCustomers. We have no relationships defined.

sum of MyCustomers TotalInvoiced

This will return the sum of what I have invoiced all my customers.

Example 2

We have two tables.CustomerType and MyCustomers. We have a relationship between them that connect CustomerType and MyCustomers on customer type.There is no Unique Alternative Name for the Relationship. I have 300 records in MyCustomer and 45 of type Good Credit. As they all buy a fixed service product that cost $10 i will have invoiced them $450.

My active record in CustomerType is the Good Credit record.

sum of MyCustomers TotalInvoiced

This will return the number $450 as I am now using the relationship instead of the table.

sum of MyCustomers named "AllRecords" 

This will return the number $3000 as I have now defined a unique relationship with no restriction and I will get the total invoiced across the table..

Example 3

sum of MyCustomers named "NewRel" with RegistrationDate=current date TotalInvoiced

This will return the total invoiced today

Example 4

for MEMBERS ;

list records

LAST NAME in order ;

sum of RESERVATIONS TOTAL DUE .

end

This script tells DataEase: (1) Process all the MEMBERS records and list each member's LAST NAME in alphabetical order, (2) for each MEMBERS record processed, find all the related records in the RESERVATIONS table (those that have the same MEMBERID), and (3) list the sum of the TOTAL DUE field for the set of RESERVATIONS records that match the current MEMBERS record.

The output from this script might look as follows:

Last Name

Sum of Reservations

Total Due

Adams

$3000.00

Albert

$4760.00

Anders

$4420.00

Andersen

$2100.00

Anderson

$4320.00

Archer...

$4796.00...

If you want to include the sum of this whole group of reservations, change the fourth line of the query to read:

 sum of RESERVATIONS TOTAL DUE : item sum .

Note: There's an important difference between the statistical operator sum and the relational statistical operator sum of. sum returns the total of the values in the specified field among the records being processed. sum of returns the total of the values in the specified field among the records related to the records being processed.


Reference

sum of

Type

Relational Statistical Operator

Purpose

The sum of operator adds the values in a specified field in all matching records in a related table. The result can appear as a list item in the detail area of a report or as a statistic in the summary area at the end of each group or at the end of the report.

Syntax

sum of TABLENAME|RELATIONSHIP

 [named "UNIQUE RELATIONSHIP NAME" ]

 [with ( selection criteria) ] FIELDNAME ; | .

Returns

A numeric value.

Example

for MEMBERS ;

list records

LAST NAME in order ;

sum of RESERVATIONS TOTAL DUE .

end

 

This script tells DataEase: (1) Process all the MEMBERS records and list each member's LAST NAME in alphabetical order, (2) for each MEMBERS record processed, find all the related records in the RESERVATIONS table (those that have the same MEMBERID), and (3) list the sum of the TOTAL DUE field for the set of RESERVATIONS records that match the current MEMBERS record.

The output from this script might look as follows:

 

 

Last Name

Sum of Reservations

 

Total Due

Adams

$3000.00

Albert

$4760.00

Anders

$4420.00

Andersen

$2100.00

Anderson

$4320.00

Archer...

$4796.00...

 

If you want to include the sum of this whole group of reservations, change the fourth line of the query to read:

 

 sum of RESERVATIONS TOTAL DUE : item sum .

 

Note: There's an important difference between the statistical operator sum and the relational statistical operator sum of. sum returns the total of the values in the specified field among the records being processed. sum of returns the total of the values in the specified field among the records related to the records being processed.

See Also


Count Of
Highest Of
Lowest Of
Mean Of

On the forum about Sum Of

[@EOF@]...

Product: . Written by alembagheri tahmas 07/12/13 at 13:37:32

Hi there,I am trying to use an external MySQL DB in dataease. I have successfully create the ODBC link and added the DB to dataease. I can also access the DB from dataease. Now, just for testing purposes, I am trying to create a simple report b...

Product: DataEase for Windows 7.x. Written by George Washington 11/04/14 at 08:26:17

no se pude exportar ahora archivos a pdf, ni a excel o otros cosa mala. en verdad creo que hace faltaen las versiones anteriores me funcionaba mas o menos bien. le hace falta a los aplicativos que se desarrollan en Dataeasegr...

Product: DataEase 8 Reporter. Written by eduardo paez 02/05/14 at 14:40:11

Thanks. Anyway I'm trying to use this fuction but it seems to me that it doesn't work on 8.2. I tried also in a DQL.There's something wrong?<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA9IAAAJ3CAYAAAB4NWk3AAAAAXNSR0IArs4...

Product: . Written by Marco Marchesi 15/02/16 at 14:50:46

[@EOF@]...

Product: Dataease [{8}]FIVE. Written by Chamil Rajindra 21/02/19 at 10:17:46

Thanks for the very good explanation!AS...

Product: . Written by afonso santos 28/10/19 at 00:50:14

I am pleased to see that the migration from Dos 4.53 is then sa 5.5 works. A really useful thing would be a compiler of SQL languages. Will you get there?Original Text:Mi compiaccio a vedere che la migrazione da Dos 4.53 è poi sa 5.5 funzio...

Product: . Written by Grossi Gioacchino 18/11/19 at 14:33:44

How can i delete a Style sheet?...

Product: Dataease [{8}]FIVE. Written by Rainer 22/03/21 at 11:13:10

I run W7 and since a few days&nbsp;Dataease 8.5 is not starting any more, do you have an idea? i installed it again but that did not help....

Product: Dataease [{8}]FIVE. Written by Rainer 08/06/21 at 14:12:40

[@EOF@]...

Product: . Written by Hiralal Rampul 01/12/21 at 17:47:10

On the blog about Sum Of


dg3_HelpView