How to Calculate Male and Female in ireport

Hi everyone

 

I am new with ireport-5.6.0

 

My Urgent Requirement is  to calculate total Male and Female from my report.

 

For Example

 

Student_Name   Gender

 

John                      Male

Rekha                   Female

Ravi                      Male

 

output:

Total Male=2

Total Female=1    

 

In my report i create Two Variable   one for male and another for female and set 

 

variable class=java.lang.Boolean

Calculation=Count

Reset Type=Column

Increment Type=Column

Variable Expression=$V{male}

 

and drag both variable in my report

 

when i click on preview its display null value

 

I am not using any sub report in my report but i add two parameter

 

i want to display my value in my column footer(column footer band)

 

I also test with my sql query

 

select count(*)  as total

  , sum( case when gender = 'male'

  then 1 else 0 end )    as male

  , sum( case when gender = 'female'

 then 1 else 0 end )    as female

 from testdb.student

where department='Computer Science '

 

when i test this query in my database(mysql) its worked perfectly but when i tryed this query in my ireport query box

 

its display wrong value

 

Thnaks in Advanced

 

Anwar

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

anwarzamal2000's picture
Joined: Dec 8 2015 - 10:21pm
Last seen: 7 years 2 months ago

1 Answer:

Example for count Male.

Define variable:

Variable class = java.lang.Integer
Calculation = Sum
ResetType = Report
Increment type = None
Variable expression = $F{gender}.equals("Male")  ? 1 : 0

sanbez's picture
5820
Joined: Jan 11 2011 - 2:06am
Last seen: 2 years 5 months ago
Feedback