Jump to content
Changes to the Jaspersoft community edition download ×

Grouping by expression? Is this possible?


bfluensee

Recommended Posts

Hi,

I am new to Jasper & iReport and have a question about printing report detail not necessarily by group but by expression I guess.

I have a result set with a column that has an amount for each record.  My result set is already ordered by amount in descending order.  Below is the desired groups.

Group 1.  amount greater than or equal to 1000

Group 2.  amount greater than 500 but less than 1000

Group 3.  amount greater than 100 but less than 500

Currently the reports prints out all of the detail but not grouped by amount.  Is it possible to do this type of grouping by expression or is there a better way to get the desired report layout? Should I use a subreport?

 

Thank you in advance for any advice you can give me.



Post Edited by bfluensee at 04/14/2010 21:11
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

you can use something like this:

($F{amount}.doubleValue() >= new BigDecimal(1000).doubleValue() ? "Group 1": ($F{amount}.doubleValue() > new BigDecimal(500).doubleValue() && $F{amount}.doubleValue() < new BigDecimal(1000).doubleValue() ? "Group 2": ($F{amount}.doubleValue() > new BigDecimal(100).doubleValue() && $F{amount}.doubleValue() < new BigDecimal(500).doubleValue() ? "Group 3": "Group 4")))

Put thos piece of code into your "Group Expression".

An other workaround is to do this in your SQL query (if you're using SQL). Create a CASE .... WHEN expression like this: (CASE   WHEN amount >= 1000 THEN 1          WHEN amount > 500 AND amount < 1000 THEN 2 ... ELSE 0   END) AS SORT. If you then put $F{SORT} in your group expression it should work like you've expected.

HTH

Christina.

Link to comment
Share on other sites

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...