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

doing an if statement in a variable


willsahsansarah

Recommended Posts

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            statusID
John                 16           approved            01
John                 16           approved            01
John                 16           inprogress          02             
Joe                   17           approved            01
Joe                   17           unsubmitted      03
Julie                 18           unsubmitted      03
Julie                 18           unsubmitted      03
Julie                 18           approved            01
Julie                 18           inprogress          02
Julie                 18           inprogress          02

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

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

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.Interger
Calculation: Count
Expression:  $F{REQID}.equals("16") && $F{STATUSID}.equals( "01" ) ? "1" : "0"
Increment type: None
Reset type: Report

Even 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

<?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 all
select 'John' as "Requester"
, 16 as "ReqID"
, 'approved' as "status"
, '01' as "statusID"
union all
select 'John' as "Requester"
, 16 as "ReqID"
, 'inprogress' as "status"
, '02' as "statusID"
union all
select 'Joe' as "Requester"
, 17 as "ReqID"
, 'approved' as "status"
, '01' as "statusID"
union all
select 'Joe' as "Requester"
, 17 as "ReqID"
, 'unsubmitted' as "status"
, '03' as "statusID"
union all
select 'Julie' as "Requester"
, 18 as "ReqID"
, 'unsubmitted' as "status"
, '03' as "statusID"
union all
select 'Julie' as "Requester"
, 18 as "ReqID"
, 'unsubmitted' as "status"
, '03' as "statusID"
union all
select 'Julie' as "Requester"
, 18 as "ReqID"
, 'approved' as "status"
, '01' as "statusID"
union all
select 'Julie' as "Requester"
, 18 as "ReqID"
, 'inprogress' as "status"
, '02' as "statusID"
union all
select '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

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