Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:10:57+00:00 2026-06-07T23:10:57+00:00

I’m trying to create a summary table using iReport. My dataset is returning a

  • 0

I’m trying to create a summary table using iReport. My dataset is returning a list of purchases made and prices. Something like

Milk, $1.23

Chicken, $5.45

Milk, $1.44

and so on. I want my table to be able to breakdown my item by product. I want a table with columns:

  • # of times product was purchased (#rows where product milk),
  • total dollar amount spent on the product (sum of prices where product is milk),
  • and average price of product (column 2 divided by column 1).

How can I do this? I have been playing around with variables and I can get a total sum of all prices, but I don’t know how to do this with a subset of the data using a more complex query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:10:58+00:00Added an answer on June 7, 2026 at 11:10 pm

    It is quite easy. You can create group on product field and two variables on this group: for counting result sum and average sum. With help of built-in variable you can calculate and display the number of elements in this group.

    This is working sample:

    <?xml version="1.0" encoding="UTF-8"?>
    <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="group_average2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="product" class="java.lang.String"/>
        <field name="price" class="java.lang.Integer"/>
        <sortField name="product"/>
        <variable name="totalSum" class="java.lang.Double" resetType="Group" resetGroup="productGroup" calculation="Sum">
            <variableExpression><![CDATA[$F{price}]]></variableExpression>
            <initialValueExpression><![CDATA[0]]></initialValueExpression>
        </variable>
        <variable name="averageSum" class="java.lang.Double" resetType="Group" resetGroup="productGroup" calculation="Average">
            <variableExpression><![CDATA[$F{price}]]></variableExpression>
            <initialValueExpression><![CDATA[0]]></initialValueExpression>
        </variable>
        <group name="productGroup">
            <groupExpression><![CDATA[$F{product}]]></groupExpression>
            <groupFooter>
                <band height="20">
                    <textField>
                        <reportElement x="0" y="0" width="122" height="20"/>
                        <box leftPadding="10" rightPadding="10">
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{product}]]></textFieldExpression>
                    </textField>
                    <textField pattern="###0.00;-###0.00">
                        <reportElement x="244" y="0" width="122" height="20"/>
                        <box leftPadding="10" rightPadding="10">
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement textAlignment="Right"/>
                        <textFieldExpression><![CDATA[$V{totalSum}]]></textFieldExpression>
                    </textField>
                    <textField>
                        <reportElement x="122" y="0" width="122" height="20"/>
                        <box leftPadding="10" rightPadding="10">
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement/>
                        <textFieldExpression><![CDATA[$V{productGroup_COUNT}]]></textFieldExpression>
                    </textField>
                    <textField pattern="###0.00;-###0.00">
                        <reportElement x="366" y="0" width="149" height="20"/>
                        <box leftPadding="10" rightPadding="10">
                            <topPen lineWidth="1.0"/>
                            <leftPen lineWidth="1.0"/>
                            <bottomPen lineWidth="1.0"/>
                            <rightPen lineWidth="1.0"/>
                        </box>
                        <textElement textAlignment="Right"/>
                        <textFieldExpression><![CDATA[$V{averageSum}]]></textFieldExpression>
                    </textField>
                </band>
            </groupFooter>
        </group>
        <pageHeader>
            <band height="19">
                <staticText>
                    <reportElement x="0" y="-1" width="122" height="20"/>
                    <box leftPadding="10" rightPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Product]]></text>
                </staticText>
                <staticText>
                    <reportElement x="122" y="-1" width="122" height="20"/>
                    <box leftPadding="10" rightPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Number of orders]]></text>
                </staticText>
                <staticText>
                    <reportElement x="244" y="-1" width="122" height="20"/>
                    <box leftPadding="10" rightPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Total sum]]></text>
                </staticText>
                <staticText>
                    <reportElement x="366" y="-1" width="149" height="20"/>
                    <box leftPadding="10" rightPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Average sum of order]]></text>
                </staticText>
            </band>
        </pageHeader>
    </jasperReport>
    

    This sample takes CSV file as datasource. You can edit query – for getting data with SQL query.

    The report design in iReport is:

    The report design

    The result will be (via preview in iReport):

    The result in iReport

    You should read this article about using variables in JasperReports and this post about using groups in JasperReports.

    Please remember that you should sort the data before group using.
    The quote from the post about grouping and sorting from the jasperforge.org:

    In order to get an accurate data representation, the data in the data source should be already ordered according to the group expressions used in the report. One can either perform data sorting through the report query, or use the <sortField/> element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.