Grouping via Expressions and Variables

Grouping via Expressions

Hello All, need a bit of help or Guidance

I Have a CSV file that hold Category/ Sub Category / Price information all as readable strings. And have used “Ireports” to generate a report that groups on Category and them Sub Category and works and looks nice,

but our client wants to go one further and have the report passed three bits of information,

I guess this would be done via Variables (can get that bit) , These bit being the Main Category they are interested in and a Price range for that category say for Example

Main Cat = “Mens Suits” and priced between £50 and £150 pounds etc

Have used Ireports new Group wizard to try and do this but all I get is abends, but Syntax checks out ok , so I am missing something or not getting Sytanx correct.

So I want to group on

$f{MainCat} = “ a passed variable” and ${Price} > “x” and < “y” x and y are also passed variables

but price is a string so needs some form of conversion into float/double etc as would X and y above This has been driving me nuts for about 1 week and I still cannot get it.

Any examples of Grouping Syntax would be good it might give me a clue, where I am going wrong as that seems a normal report request from a client.
AndyDavis51's picture
Joined: Oct 9 2006 - 7:49am
Last seen: 3 years 3 months ago

2 Answers:

Hi Andy,

Sounds like there is some confusion between filtering and grouping. The GroupBy expression allows you group related records, and all records that have the same return value for the GroupBy expression will be in the same bunch. In you example where the expression is ?$f{MainCat} = “ a passed variable” and ${Price} > “x” and < “y” you are going to have two groups, one for "true" and one for "false".

I think you want to filter the data, right? In other words, only show the data for items in the given category and in the price range. Normally you would pass that info to the query and let the datasource do the filtering, but you can't do that with a CSV file of data.

You might be able to add a printWhenExpression to the detail band to only print when the data matches your conditions, but I'm not sure if its evaluated on each iteration or not.

Finally, you pass values into a report via Parameters, not Variables.

-Barry
bklawans's picture
4020
Joined: Jul 6 2006 - 1:21pm
Last seen: 6 years 2 months ago
If you use JR >= 1.2.5, you can also use <filterExpression> to filter the report data source.

You can see this in the "csvdatasource" sample distributed with JR.

Regards,
Lucian
lucianc's picture
76744
Joined: Jul 17 2006 - 1:10am
Last seen: 6 hours 6 min ago
Feedback
randomness