willsahsansarah Posted June 24, 2020 Share Posted June 24, 2020 I have 3 requesters who put in 10 forms and they are in 3 different type of status. I want to create a count of that and group it by requesters and different type. I don't want to do this in the query but as a field/variable. I tried creating a vailable: $F{REQID} ==16 && $F{STATUSID} ==01? 1:0 I tried this for every combo for reqID 16 and set the calulation to count but I got nothing.Requester ReqID status statusIDJohn 16 approved 01John 16 approved 01John 16 inprogress 02 Joe 17 approved 01Joe 17 unsubmitted 03Julie 18 unsubmitted 03Julie 18 unsubmitted 03Julie 18 approved 01Julie 18 inprogress 02Julie 18 inprogress 02 Link to comment Share on other sites More sharing options...
jgust Posted June 25, 2020 Share Posted June 25, 2020 You can use the 'equals' method also it looks like the STATUSID is a string and should be wrapped in quotes.$F{REQID}.equals( 16 ) && $F{STATUSID}.equals( "01" ) ? 1 : 0[/code]Here is the same expression this time with multiple conditions:$F{ReqID}.equals( 16 ) && $F{statusID}.equals( "01" ) ? 1 : $F{ReqID}.equals( 16 ) && $F{statusID}.equals( "02" ) ? 2 : $F{ReqID}.equals( 17 ) && $F{statusID}.equals( "03" ) ? 3 : 0[/code] Link to comment Share on other sites More sharing options...
willsahsansarah Posted June 26, 2020 Author Share Posted June 26, 2020 Both are strings so I tried $F{REQID}.equals("16") && $F{STATUSID}.equals( "01" ) ? "1" : "0" In the real data, the count should be 5 if I used the $F{REQID}.equals("16") && $F{STATUSID}.equals( "01" ) ? "1" : "0" instead I get a count 0f 160 (which is the overall count). The following are my variable constraints:Value Class Name: java.lang.IntergerCalculation: CountExpression: $F{REQID}.equals("16") && $F{STATUSID}.equals( "01" ) ? "1" : "0"Increment type: NoneReset type: ReportEven if I don't do a boolan condition and just do $F{REQID}.equals("16") && $F{STATUSID}.equals( "01" ) I get the count 160. Link to comment Share on other sites More sharing options...
jgust Posted June 26, 2020 Share Posted June 26, 2020 The IF statement now works for you since you were getting nothing and now you're getting an overstated amount. At this point, the issue sounds like you need to look at the increment type and reset type on the variable. Link to comment Share on other sites More sharing options...
Tom C Posted June 26, 2020 Share Posted June 26, 2020 The easiest way to do this is to use group feature in JasperReports design template. Link to comment Share on other sites More sharing options...
Tom C Posted June 26, 2020 Share Posted June 26, 2020 <?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 7.5.0.final using JasperReports Library version 6.4.0 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Report4Sarah" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2cf2451d-f421-4a66-b878-50a67ddeb031"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JRSrepo"/> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <queryString> <![CDATA[select 'John' as "Requester", 16 as "ReqID", 'approved' as "status", '01' as "statusID"union allselect 'John' as "Requester", 16 as "ReqID", 'approved' as "status", '01' as "statusID"union allselect 'John' as "Requester", 16 as "ReqID", 'inprogress' as "status", '02' as "statusID"union allselect 'Joe' as "Requester", 17 as "ReqID", 'approved' as "status", '01' as "statusID"union allselect 'Joe' as "Requester", 17 as "ReqID", 'unsubmitted' as "status", '03' as "statusID"union allselect 'Julie' as "Requester", 18 as "ReqID", 'unsubmitted' as "status", '03' as "statusID"union allselect 'Julie' as "Requester", 18 as "ReqID", 'unsubmitted' as "status", '03' as "statusID"union allselect 'Julie' as "Requester", 18 as "ReqID", 'approved' as "status", '01' as "statusID"union allselect 'Julie' as "Requester", 18 as "ReqID", 'inprogress' as "status", '02' as "statusID"union allselect 'Julie' as "Requester", 18 as "ReqID", 'inprogress' as "status", '02' as "statusID"]]> </queryString> <field name="Requester" class="java.lang.String"> <property name="com.jaspersoft.studio.field.label" value="Requester"/> </field> <field name="ReqID" class="java.lang.Integer"> <property name="com.jaspersoft.studio.field.label" value="ReqID"/> </field> <field name="status" class="java.lang.String"> <property name="com.jaspersoft.studio.field.label" value="status"/> </field> <field name="statusID" class="java.lang.String"> <property name="com.jaspersoft.studio.field.label" value="statusID"/> </field> <sortField name="ReqID"/> <sortField name="statusID"/> <group name="Requester"> <groupExpression><![CDATA[$F{Requester}]]></groupExpression> <groupFooter> <band height="35"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField> <reportElement x="380" y="0" width="100" height="30" forecolor="#0066FF" uuid="b5b5bdcd-c184-44b4-a560-a97bbcdbabb3"/> <textFieldExpression><![CDATA[$V{Requester_COUNT}]]></textFieldExpression> </textField> <textField> <reportElement x="0" y="2" width="180" height="30" forecolor="#0066FF" uuid="5536fa4f-78be-47f8-8623-088864c486e2"/> <textFieldExpression><![CDATA[$F{Requester}]]></textFieldExpression> </textField> <staticText> <reportElement x="280" y="0" width="100" height="30" forecolor="#0066FF" uuid="b683c5d6-2955-4004-ae88-c7a7f40a2a85"/> <textElement textAlignment="Right"/> <text><![CDATA[count: ]]></text> </staticText> </band> </groupFooter> </group> <group name="Status"> <groupExpression><![CDATA[$F{status}]]></groupExpression> <groupFooter> <band height="35"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField> <reportElement x="280" y="0" width="100" height="30" forecolor="#009900" uuid="a7f62dab-98ef-4f4b-9b01-210c66f361f0"/> <textFieldExpression><![CDATA[$V{Status_COUNT}]]></textFieldExpression> </textField> <textField> <reportElement x="0" y="0" width="180" height="30" forecolor="#009900" uuid="8a5e61bd-57b0-48f1-bd94-3df90dbaa03d"/> <textFieldExpression><![CDATA[$F{Requester}+" ("+$F{status}+") "]]></textFieldExpression> </textField> <staticText> <reportElement x="180" y="0" width="100" height="30" forecolor="#009900" uuid="fed30868-f6b1-4631-96b0-7913c6de487f"/> <textElement textAlignment="Right"/> <text><![CDATA[count: ]]></text> </staticText> </band> </groupFooter> </group> <background> <band splitType="Stretch"/> </background> <title> <band height="35" splitType="Stretch"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <staticText> <reportElement x="0" y="0" width="570" height="30" forecolor="#FF0000" uuid="7604b8be-7f2e-4aee-be8c-247bd4357328"/> <textElement textAlignment="Center"> <font size="18" isBold="true"/> </textElement> <text><![CDATA[sample Report]]></text> </staticText> </band> </title></jasperReport> Link to comment Share on other sites More sharing options...
Tom C Posted June 26, 2020 Share Posted June 26, 2020 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now