Grouping on calculated Columns
Posted: Wed Sep 30, 2009 9:24 am
Hi All,
Next problem I have come across converting a crystal report...
I am using a calculated column to generate a field to group some data with. In our crystal report this looks like:
numbervar groupNo;
If trim({command.PND_BARCODE}) = '*SECTION/*'
then groupNo := groupNo +1
else groupNo := groupNo
So nothing special...
This looks in a field for some specific text, everytime it finds this it increments groupNo by one and sets this in the detail section of the report for each record.
The sqlquery that pulls the data in sorts the records by a specific sequence that ensures all items below the '*SECTION/*' are in the correct order.
The resulting data runs correctly in Crystal.
I have re-created the sql statement, created a variable in my report that is an INT with a default value of '0' then created a calulated column to reproduce the Crystal format as follows:
(invoice.PND_BARCODE.Trim() == "*SECTION/*" ? SectionGroupNo = SectionGroupNo + 1: SectionGroupNo)
When I run the report without any grouping, the new Calculated Column is reproducing what I expect correctly,
eg.
GrpNo sqlSequence Code
1 ........ 1 .......... *SECTION/*
1 ........ 2 .......... 1234
1 ........ 3 .......... abc
1 ........ 4 .......... zzz
2 ........ 5 .......... *SECTION/*
2 ........ 6 .......... xxxx
2 ........ 7 .......... 9234
so next I apply a group header, setting this calculated column to be what is used for the grouping and add a group footer below the detail band.
This throws the calculated column way off & it is now no longer performing as expected.
The Calculated column begins not at 1 anymore but at 4 & increments on the correct record, the next after & the one just before in a sequence.
You will notice however that the sqlSequence sort order of the data is still correct
eg
Group Head GrpNo=4
GrpNo sqlSequence Code
5 .......... 1 .......... *SECTION/*
6 .......... 2 .......... 1234
6 .......... 3 .......... abc
7 .......... 4 .......... zzz
Group Head GrpNo=10
GrpNo sqlSequence Code
11 .......... 5 .......... *SECTION/*
12 .......... 6 .......... xxxx
12 .......... 7 .......... 9234
I feel that I have to get the calculated column to be generated before the grouping, but then not be changed after the grouping?
or am I on the wrong track here as to what is going wrong?
Any Ideas?
many thanks in advance
Next problem I have come across converting a crystal report...
I am using a calculated column to generate a field to group some data with. In our crystal report this looks like:
numbervar groupNo;
If trim({command.PND_BARCODE}) = '*SECTION/*'
then groupNo := groupNo +1
else groupNo := groupNo
So nothing special...
This looks in a field for some specific text, everytime it finds this it increments groupNo by one and sets this in the detail section of the report for each record.
The sqlquery that pulls the data in sorts the records by a specific sequence that ensures all items below the '*SECTION/*' are in the correct order.
The resulting data runs correctly in Crystal.
I have re-created the sql statement, created a variable in my report that is an INT with a default value of '0' then created a calulated column to reproduce the Crystal format as follows:
(invoice.PND_BARCODE.Trim() == "*SECTION/*" ? SectionGroupNo = SectionGroupNo + 1: SectionGroupNo)
When I run the report without any grouping, the new Calculated Column is reproducing what I expect correctly,
eg.
GrpNo sqlSequence Code
1 ........ 1 .......... *SECTION/*
1 ........ 2 .......... 1234
1 ........ 3 .......... abc
1 ........ 4 .......... zzz
2 ........ 5 .......... *SECTION/*
2 ........ 6 .......... xxxx
2 ........ 7 .......... 9234
so next I apply a group header, setting this calculated column to be what is used for the grouping and add a group footer below the detail band.
This throws the calculated column way off & it is now no longer performing as expected.
The Calculated column begins not at 1 anymore but at 4 & increments on the correct record, the next after & the one just before in a sequence.
You will notice however that the sqlSequence sort order of the data is still correct
eg
Group Head GrpNo=4
GrpNo sqlSequence Code
5 .......... 1 .......... *SECTION/*
6 .......... 2 .......... 1234
6 .......... 3 .......... abc
7 .......... 4 .......... zzz
Group Head GrpNo=10
GrpNo sqlSequence Code
11 .......... 5 .......... *SECTION/*
12 .......... 6 .......... xxxx
12 .......... 7 .......... 9234
I feel that I have to get the calculated column to be generated before the grouping, but then not be changed after the grouping?
or am I on the wrong track here as to what is going wrong?
Any Ideas?
many thanks in advance