Suppose you’re tracking sales and want to generate a summary report, grouped by quarter. The data stores the actual date, so you’ll need to calculate the quarter.

To calculate the quarter, divide the month of the date by 3 and round up:

Month

Month number

Divided by 3

Rounded up

January

1

1/3

1

March

3

1

1

April

4

1 1/3

2

December

12

4

4

You can add the calculated field in the query’s onOpen event:

function sales1_onOpen( )

local c 

   c = new Field( ) // Create a new Field object 

   c.fieldName := "Quarter" // Give it a name 

   this.rowset.fields.add( c ) // Add it to the fields array 

   c.beforeGetValue := {||ceiling( month( this.parent.fields[ "Date" ].value ) / 3 )} 

The group’s groupBy property is set to "Quarter". You still need to sort the report by date so that the groups will be in the right order. You can’t use autoSort, since it will try to sort by a field named "Quarter", and there isn’t one. So you use the following SQL SELECT statement in the query’s sql property:

select * from OVERTIME order by OVERTIME."DATE"

DATE is an SQL reserved word, so you need to place the field name in quotes and use the table name.