Jump to content
We've recently updated our Privacy Statement, available here ×

Grouping counts after all data


asfernandes

Recommended Posts

Let's say you have this data source:

 

State   City             Sales

SP      São Paulo           10

SP      Ribeirão Preto       5

RJ      Rio de Janeiro       8

RJ      Campos               3

 

And you want a report that 1) Print this table; and 2) Print the counts per state in the end:

 

State   Sales

SP         15

RJ         11

 

Is there a way to use groups and put the counts per state right after all cities? Or what's the recommended way to do it?

 

Thanks.

 

 

Adriano
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Easy to do this in SQL and just have a subreport with the summary information. If your data source isn't SQL then maybe something like this would help.

 $V{countOfSP}

$V{countOfRJ}

 

Now you have a variable expression where you set the resulting value of the variable to either 0 or 1 based on the rows value. Put this code in the $V{countOfSP} variable and place it on the row (set the print when expression = Boolean.FALSE so it doesn't ever show this on the report)

($F{state}.equals("SP")) ? 1 : 0

Then create a sum variable in the appropriate summary band as needed for each of the countOf##### variables. Should result in a sum represending the count of each type, once you have that you can format it in output however you like.

Just for a little more clarification, each one of the variables "countOfSP, countOfRJ" etc should have the appropriate equal check,

 

$V{countOfSP} with expression = ($F{state}.equals("SP")) ? 1 : 0

$V{countOfRJ} with expression = ( $F{state}.equals("RJ")) ? 1 : 0

In the bottom of the report your sum's should be good to just layout howver you like.

Hope this helps,

Clark

Link to comment
Share on other sites

I'm looking for better alternatives than rewrite a possible long and slow query in a subreport to display things that already could be computed while passhing through the data.


Sorry, but I don't believe in what you suggested about hardcoding tests for each state (or whatever). This is something against any well programming practice, and I'm looking for a better (generic) way to solve problems.

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