Jump to content
Changes to the Jaspersoft community edition download ×

Group expression


Recommended Posts

By: Vadim Koustov - vadimk

Group expression

2002-08-20 13:37

Anybody knows how to write GroupExpression or VariableExpression in case if I want to group by two fields, for example code and subcode.

I expect to see some thing like that:

$F{code} and $F{subcode}

 

Any suggestions please.

 

Thanks for your help

 

 

By: Teodor Danciu - teodord

RE: Group expression

2002-08-21 01:50

 

Hi,

 

First, you have to make sure you don't want to

have two groups: one for the code and inside it,

the subcode group.

 

If you're sure you want to have a single group that

breaks every time the combination code/subcode

changes, than in the group expression you have

to somehow compute those fields in order to obtain

a value that will change whenever the

code/subcode combination changes.

 

But this expression heavily depends on the types

and structure of your code and subcode fields.

And remember that all JasperReports expressions

are in fact real Java expression, except that we

have added a special syntax to introduce report

parameter, field and variable references

(those $X{} references).

 

Lets say that both of your fields are String objects.

We could make a composite value just

by concatenating them like this in the group

expression:

 

$F{code} + $F{subcode}

 

But that won't avoid a situation in which we could

have two different combinations of code and

subcode with the same concatenated value and

the group won't break as expected:

 

code="123", subcode="456" --> value="123456"

code="12", subcode="3456" --> value="123456"

 

A solution would be to introduce a special

separator like this:

$F{code} + "|" + $F{subcode}

 

code="123", subcode="456" --> value="123|456"

code="12", subcode="3456" --> value="12|3456"

 

Or to control the length of each field and preserve

it in the concatenated value.

 

Things are not very different even if the two fields

are numbers.

 

The idea behind all this is to create a composite

value that will preserve the group break behavior as

expected when those two fields change their values.

 

You have to make sure also that the rows of your

data source are sorted by code and subcode,

in this order.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...