Jump to content
Changes to the Jaspersoft community edition download ×

Variable problem


2004 IR Help

Recommended Posts

By: Matihost - matihost

Variable problem

2005-09-01 14:14

I have data:

 

2005-08-01 100

2005-08-01 200

2005-08-01 300

2005-08-02 50

2005-08-02 150

 

and i`d like get a report like this:

 

2005-08-01 20 %

2005-08-01 40 %

2005-08-01 40 %

 

2005-08-02 25 %

2005-08-02 75 %

 

Am using grouping and i`ve create a variable which is a sum of second column calculating for each group, but this field has strange value... (last two column are within one text field) for example:

 

2005-08-01 100 -- field 100 --- sum

2005-08-01 200 300

2005-08-01 300 600

2005-08-02 50 50

2005-08-02 150 200

 

last column is value of that variable calculating "Now", but if i change expression to calculating "Group" the result is

 

2005-08-01 300 -- field 600 --- sum

2005-08-01 300 600

2005-08-01 300 600

2005-08-02 150 200

2005-08-02 150 200

 

Solution is to evaluate field as now and variable sum as group in one expresion or save evaluated variable sum in some sort of other variable.... If somebody find solution to my problem, i would be appreciated.

 

Thanks in advance, Mati

 

 

 

 

 

 

 

By: jorge - sirion_oef

RE: Variable problem

2005-09-02 17:20

could you provide more details of what you want to do?

 

what calculation do you want to do? what are the exact formulas?

 

the data you posted is just an example or is real data?

 

 

 

 

By: Matihost - matihost

RE: Variable problem

2005-09-04 03:26

Yes, this the shortcut of real data.

 

I have two fields $F{DATE} and $F{VALUE} sorted by DATE.

(select DATE, VALUE from blabla order by DATE).

I`ve create a group DATE_GROUP and create variables VALUES_SUM and PERCENT. I`d like to display percent value at details band. So I created a variable sum and i divide field value by sum. Textfield with expresion $V{PERCENT} in details section with calculating "group" returns only correct result for last item, calculating "now" returns incorrect variable VALUES_SUM as sum of previous items, so percent is incorrect also.

 

 

I`m using IReport 0.5.1.

 

Report xml:

 

- <jasperReport name="percent_simple" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false" language="java" isFloatColumnFooter="false" whenResourceMissingType="Null">

<property name="ireport.scriptlethandling" value="2" />

<import value="java.util.*" />

<import value="net.sf.jasperreports.engine.*" />

<import value="net.sf.jasperreports.engine.data.*" />

- <queryString>

- <![CDATA[ select date,value from simple order by date

]]>

</queryString>

<field name="date" class="java.lang.String" />

<field name="value" class="java.lang.Integer" />

- <variable name="VALUES_SUM" class="java.lang.Integer" resetType="Group" resetGroup="DATE_GROUP" calculation="Sum" incrementType="None">

- <variableExpression>

- <![CDATA[ $F{value}

]]>

</variableExpression>

</variable>

- <variable name="PERCENT" class="java.lang.Double" resetType="Report" calculation="Nothing" incrementType="None">

- <variableExpression>

- <![CDATA[ new Double(((double)$F{value}.intValue())/$V{VALUES_SUM}.intValue())

]]>

</variableExpression>

</variable>

- <group name="DATE_GROUP" isStartNewColumn="false" isStartNewPage="false" isResetPageNumber="false" isReprintHeaderOnEachPage="false" minHeightToStartNewPage="0">

- <groupExpression>

- <![CDATA[ $F{date}

]]>

</groupExpression>

- <groupHeader>

- <band height="50" isSplitAllowed="true">

- <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Group" evaluationGroup="DATE_GROUP" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">

<reportElement mode="Transparent" x="139" y="29" width="100" height="18" forecolor="#000000" backcolor="#FFFFFF" key="textField" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000" />

- <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" isStyledText="false">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded="false" pdfEncoding="Cp1252" isStrikeThrough="false" />

</textElement>

- <textFieldExpression class="java.lang.Integer">

- <![CDATA[ $V{VALUES_SUM}

]]>

</textFieldExpression>

</textField>

</band>

</groupHeader>

- <groupFooter>

<band height="50" isSplitAllowed="true" />

</groupFooter>

</group>

- <background>

<band height="0" isSplitAllowed="true" />

</background>

- <title>

<band height="0" isSplitAllowed="true" />

</title>

- <pageHeader>

<band height="0" isSplitAllowed="true" />

</pageHeader>

- <columnHeader>

<band height="0" isSplitAllowed="true" />

</columnHeader>

- <detail>

- <band height="18" isSplitAllowed="true">

- <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">

<reportElement mode="Transparent" x="32" y="0" width="100" height="18" forecolor="#000000" backcolor="#FFFFFF" key="textField" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000" />

- <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" isStyledText="false">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded="false" pdfEncoding="Cp1252" isStrikeThrough="false" />

</textElement>

- <textFieldExpression class="java.lang.String">

- <![CDATA[ $F{date}

]]>

</textFieldExpression>

</textField>

- <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">

<reportElement mode="Transparent" x="132" y="0" width="100" height="18" forecolor="#000000" backcolor="#FFFFFF" key="textField" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000" />

- <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" isStyledText="false">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded="false" pdfEncoding="Cp1252" isStrikeThrough="false" />

</textElement>

- <textFieldExpression class="java.lang.Integer">

- <![CDATA[ $F{value}

]]>

</textFieldExpression>

</textField>

- <textField isStretchWithOverflow="false" pattern="#,##0 %" isBlankWhenNull="false" evaluationTime="Group" evaluationGroup="DATE_GROUP" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">

<reportElement mode="Transparent" x="233" y="0" width="100" height="18" forecolor="#000000" backcolor="#FFFFFF" key="textField" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000" />

- <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" isStyledText="false">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded="false" pdfEncoding="Cp1252" isStrikeThrough="false" />

</textElement>

- <textFieldExpression class="java.lang.Double">

- <![CDATA[ $V{PERCENT}

]]>

</textFieldExpression>

</textField>

- <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Group" evaluationGroup="DATE_GROUP" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">

<reportElement mode="Transparent" x="336" y="0" width="79" height="18" forecolor="#000000" backcolor="#FFFFFF" key="textField-1" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000" />

- <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" isStyledText="false">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded="false" pdfEncoding="Cp1252" isStrikeThrough="false" />

</textElement>

- <textFieldExpression class="java.lang.String">

- <![CDATA[ $F{value} +" " +$V{VALUES_SUM}

]]>

</textFieldExpression>

</textField>

- <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" bookmarkLevel="0">

<reportElement mode="Transparent" x="424" y="0" width="100" height="18" forecolor="#000000" backcolor="#FFFFFF" key="textField-2" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000" />

- <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" isStyledText="false">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded="false" pdfEncoding="Cp1252" isStrikeThrough="false" />

</textElement>

- <textFieldExpression class="java.lang.String">

- <![CDATA[ $F{value} +" " +$V{VALUES_SUM}

]]>

</textFieldExpression>

</textField>

</band>

</detail>

- <columnFooter>

<band height="0" isSplitAllowed="true" />

</columnFooter>

- <pageFooter>

<band height="0" isSplitAllowed="true" />

</pageFooter>

- <summary>

<band height="0" isSplitAllowed="true" />

</summary>

</jasperReport>

 

 

 

 

By: jorge - sirion_oef

RE: Variable problem

2005-09-05 08:44

try setting VALUE_SUM and PERCENT evaluation time to group, and a textfield fieldvalue/sum evaluation time to now

 

 

 

 

By: Matihost - matihost

RE: Variable problem

2005-09-05 10:55

Maybe I don`t understand, but variable doesn`t contain evaluation time parameter, only textfield contains. I`ve tried to set reset type "group" for VALUE_SUM and PERCENT variables, and texfield evaluation time set to now but result is that, variable VALUE_SUM with evaluating now contains only sum of previous items. For example:

200 100 %

300 60 %

100 17 %

because variable VALUE_SUM with evaluating "now" are:

200

500

600

The result is that, only last percent value is correct, because only last sum is sum of all items.

 

Evaluating "group" for textfield value/sum has similar problem: sum is ok, but value is last value of the group.

 

The solution is to divide two variables evaluating in different time. Field value : now and variable SUM_VALUE to group, but it is impossible in jasper probably :(

 

 

 

 

 

 

By: jorge - sirion_oef

RE: Variable problem

2005-09-06 17:02

why impossible?

 

just do that, create two variables managin the same field, but with diferents evaluating times

 

 

 

 

By: Matihost - matihost

RE: Variable problem

2005-09-07 01:28

I`ve created variable

<variable name="VALUES_SUM" class="java.lang.Integer" resetType="Group" resetGroup="DATE_GROUP" calculation="Sum">

<variableExpression><![CDATA[

$F{value}]]></variableExpression>

</variable>

 

and textfield:

<textField isStretchWithOverflow="false" pattern="#,##0 %" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

...

<textFieldExpression class="java.lang.Double"><![CDATA[new Double((double)$F{value}.intValue()/$V{VALUES_SUM}.doubleValue())]]></textFieldExpression>

</textField>

 

and result is that, i described in previous message.

Maybe I`m doing the same error. Please correct me. I don`t know to change evaluating time in the same textfield.

 

Thank You in advance

Mati

 

 

 

 

 

By: jorge - sirion_oef

RE: Variable problem

2005-09-07 17:36

could you send me the .jrxml file? i can open the text that yu posted

 

eisenrich@hotmail.com

 

 

 

 

 

By: Matihost - matihost

RE: Variable problem

2005-09-13 07:37

http://student.agh.edu.pl/~nowakow/jasper/percent_simple.jrxml

 

If you can test it, i`ll be appreciated.

 

Thanks in advance

Mati

 

 

 

 

 

 

By: jorge - sirion_oef

RE: Variable problem

2005-09-14 12:08

sorry, i have been very busy these days

 

i still don?t understand what you want, could you post sometingh like:

 

record 1:

value = , VALUES_SUM= , PERCENT=

(and all the output data that must appear in the details section for this record)

 

record 2: ...

 

 

 

 

 

 

 

By: Matihost - matihost

RE: Variable problem

2005-09-14 14:10

I want to get:

 

details1:

value=100 sum=600 percent=16 %

 

detail2:

value=200 sum=600 percent=33 %

 

detail3:

value=300 sum=600 percent=50 %

 

But i get (variables SUM and PERCENT evaluation time "now" or "band")

details1:

value=100 sum=100 percent=100 %

 

detail2:

value=200 sum=300 percent=66 %

 

detail3:

value=300 sum=600 percent=50 %

 

or (variables SUM and PERCENT evaluation time "group"):

details1:

value=300 sum=600 percent=50 %

 

detail2:

value=300 sum=600 percent=50 %

 

detail3:

value=300 sum=600 percent=50 %

 

 

 

 

By: jorge - sirion_oef

RE: Variable problem

2005-09-14 17:21

for your SQL query try:

 

select date,value, SUM(value) AS Total from simple group by date

 

when you need the total for the group use $F{Total}

 

in your report are 5 textfields, what values you want for them?

 

record1 (from left to right)

field1=

field2=

field3=

field4=

field5=

value=

VALUES_SUM=

PERCENT=

 

record2....

 

 

 

 

By: Matihost - matihost

RE: Variable problem

2005-09-15 02:08

I solve this problem in the same way (sum in sql), and thank You for the answer, but i`m trying to find another solution, because this is expensive solution for my reports :(

 

Is there any way to evaluate two or more variables in different evaluation scopes ??

 

Or is there way to get textfield value and use it in another textfield expression??

 

Don`t bother again about this sample jrxml file, this is only an example.

 

Thank You again for Your answers and time

Mati

 

 

 

 

By: jorge - sirion_oef

RE: Variable problem

2005-09-15 09:01

if your data no changes often, try creating a temp table that only contains the totals.

 

about your two questions, at least i don?t know how to do that, sorry

 

 

 

 

By: Matihost - matihost

RE: Variable problem

2005-09-16 01:09

Thanks for Your help and time. I think solving these questions would be nice enhacement in jasper.

 

Thank You again

Mati

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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