Menu
  • HOME
  • TAGS

How do I perform percentage wise calculation in reports?

Tag: jasper-reports

I am trying to build a report of the following format:

Some Column A | Some Column B | Some Column C | Percentage Allocation
-------------------------------------------------------------
Value N       | Value B       | 100           | 10%
Value C       | Value S       | 200           | 20%
Value D       | Value Y       | 300           | 30%
Value A       | Value X       | 400           | 40%
-------------------------------------------------------------
                              | 1000          |

The Percentage_Allocation column should be calculated like this: 100/1000 * 100

I have created two variables:

GRAND_TOTAL defined as the sum of the values in Column C and PERCENT_ALLOCATION defined as Field value of Column C divided by GRAND_TOTAL

The output I get is:

Some Column A | Some Column B | Some Column C | Percentage Allocation
-------------------------------------------------------------
Value N       | Value B       | 100           | 100%
Value C       | Value S       | 200           | 66%
Value D       | Value Y       | 300           | 50%
Value A       | Value X       | 400           | 40%
-------------------------------------------------------------
                              | 1000          |

I understand that this is happening because the value of PERCENT_ALLOCATION is being calculated as and when a new row is created on the report. But I want it to be calculated only when all the details have been loaded. Maybe this is not possible? I don't know, is there something I can do to achieve my target output?

UPDATE:

So I've figured out that there's a property called Evaluation Time which can help me decide when the column PERCENT_ALLOCATION should be calculated. I have set it to Report so that the value of GRAND_TOTAL takes the sum of all the values in Column C. But now I find that PERCENT_ALLOCATION is being calculated using the last value in Column C only. So my report looks like this:

Some Column A | Some Column B | Some Column C | Percentage Allocation
-------------------------------------------------------------
Value N       | Value B       | 100           | 40%
Value C       | Value S       | 200           | 40%
Value D       | Value Y       | 300           | 40%
Value A       | Value X       | 400           | 40%
-------------------------------------------------------------
                              | 1000          |

Thanks.

Best How To :

Do not calculate the percent in a variable. Perform the calculation in a Text Field in the report. Use the field value of Some Column C and divide it by the GRAND_TOTAL variable.

Field not found in jasperreports 3.5.3

jasper-reports,ireport

You're using this field inside a List. You should declare as a field of the dataset your list is using. Like this: <?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="report1" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802"...

How to generate a doc file using Jasper Report

java,jasper-reports,doc

Try like this JasperPrint jasperPrint = JasperFillManager.fillReport("myReport.jasper", reportParameters, dataSource); Exporter exporter = new JRDocxExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); File exportReportFile = new File("D:\\Temp\\report.docx"); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(exportReportFile)); exporter.exportReport(); HTH...

iReport : set a fixed height for detail band

jasper-reports,ireport

You can use background band to form a grid structure like below, <background> <band height="555" splitType="Stretch"> <rectangle> <reportElement x="0" y="59" width="555" height="427" uuid="ee3fa6a5-eddb-4b38-b834-f2658bcf92d1"/> </rectangle> <line> <reportElement x="0" y="95" width="555" height="1" uuid="4494e946-4ff5-4d57-b3eb-9d64eda302c4"/> </line> <line> <reportElement x="0" y="125" width="555" height="1" uuid="4494e946-4ff5-4d57-b3eb-9d64eda302c4"/> </line>...

How to get date six month before current date in single line in Java?

java,jasper-reports

wrap this util method into a Utility class build the jar and put it in classpath of your iReport and whenever you are compiling this jrxml

Download Jasper report instead of opening in browser

jsf,jasper-reports

You are very close to it. just add attachment; statement with the filename=xx.pdf Like: httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf"); It tells Http Servlet Responce that the file contains is attachment; Extra: Whenever browser opens PDF format it also shows saving option you can also save it after opening(loading) in browser...

cascading Input Control sql query return error: “ORA-01427: single-row subquery returns more than one row”

oracle,jasper-reports,jasperserver

You're doing an uncorrelated subquery to get the first/last name from the user table. There is no relationship between that subquery: SELECT CONCAT(first_name, surname) AS user_name from tbl_user ... and the user ID in the main query, so the subquery will attempt to return every first/last name for all users,...

JasperReport with spring MVC : print report on client side without displaying it

java,angularjs,spring-mvc,printing,jasper-reports

You can create an object in HTML page which hold PDF & then print it using print() method or use java.awt.print.PrinterJob. See below examples. Print embedded PDF from browser with Javascript, HTML5, AngularJS Print a PDF from the browser Print PDF directly from JavaScript Print JasperPrint directly to printer ?...

How to install JasperReports as an Eclipse plugin with no internet connection? [duplicate]

java,plugins,eclipse-plugin,jasper-reports

You can download the files from another computer and put it in a usb. I guess if you have connection for stackoverflow, you might have enough for downloading files. The procedure is shown here what I used before: open Eclipse: Help -> Install New Software... -> Add -> Archive.... Another...

Does JDK 8 supports JasperReports 6?

java,jasper-reports,java-8

I just figured out the issue after trying few days. My report didn't work not due to an incompatibility issue. But because i haven't used JasperPrint jp = JasperFillManager.fillReport(jr, param, new JREmptyDataSource()); instead of JasperPrint jp = JasperFillManager.fillReport(jr, param); Yes. JDK 8 is compatible with JasperReports 6. JasperReports doesn't have...

Visualize.js authentication error after second login

jasper-reports,visualize

This seemed to have worked for me. So I called visualize.config( config ) first so that I can store common configuration, to share them between visualize calls and then called the login method so that I can perform authentification with provided auth object. My reference: http://community.jaspersoft.com/wiki/visualizejs-api-notes-and-samples-v56 visualize.config( config ); visualize(...

JBOSS 7.1.1 server hangs during the compilation of jasper reports

java,jboss,jasper-reports,client,server

So, what actually happens is that there were some errors and they weren't shown in the log when I tested with the WAR file. But when I tested with the WAR folder from my developer JBOSS it showed the errors.

DynamicJasper & Webstart

java,jasper-reports,java-web-start,dynamic-jasper

My Bad. Missing JDT Compiler in classpath. And it worked with a "standard" jasper report because it was a pre-compiled .jasper report.

Why can't I reference net.sf.jasperreports.engine.DefaultJasperReportsContext from JSF?

java,jsf,jasper-reports

JasperSoft and support libraries cannot be copied into source as class files (unlike what is commonly done with other support libraries in desktop applications for JWS), they must be referenced as true libraries.

iReport could not parse mapping document

hibernate,jasper-reports,ireport

iReport ships and works with Hibernate version 3 (I'm not entirely sure how to check the exact version, quick google search suggests 3.0.5). That means, that your mapping file needs to be compliant with that version. Or, you could pull the data from database using your java application and use...

How to pass fields from parent to sublist in JasperReports?

java,jasper-reports

Try passing it as a parameter. <datasetRun subDataset="sublist"> <datasetParameter name="username"> <datasetParameterExpression><![CDATA[$F{username}]]></datasetParameterExpression> </datasetParameter> </datasetRun> ...

Jasper - Oracle - query result table is repeated

oracle,jasper-reports,rownum

AND rownum<=1 is correct. It must just be added in the main query - not a sub-dataset. :)

Dot matrix printer is not continuing with half letter paper size

pdf,printing,jasper-reports,dot-matrix

Problem was with the page margins; I remove the page margins and now it can be print continuously on half letter size paper.

How to put Subtotal in multiple col cells?

jasper-reports,dynamic-reports

Worked with some tricks Class ComponentPosition private static void recalculateWidth(String name, DRDesignList list, int availableWidth) throws DRException { for (int i=0;i<list.getListCells().size();i++) { DRDesignListCell listCell = list.getListCells().get(i); DRDesignComponent component = listCell.getComponent(); if (component instanceof DRDesignList){ for (DRDesignComponent cp : ((DRDesignList)component).getComponents()){ Integer colSpan = colSpans.get( cp.getName() ); if (colSpan!=null){ int w =...

DynamicReports/JasperReports third party unicode Font issue

java,pdf,printing,jasper-reports,dynamic-reports

Alright, no answer so better answer my own question. The issue was that this font i am using and many other fonts (about 80% of my collection of urdu fonts) are behaving same. Where some other fonts are working good, i have created a list of fonts which worked for...

Jasper Reports:java.sql.SQLException: ORA-22905: cannot access rows from a non-nested table item

oracle,plsql,jasper-reports

you can try to CAST: select * from table(CAST(VENDOR_TYPE($P{report_no}) AS VENDOR_TYPE)) ...

How to put two jasperReports in one zip file to download?

jsf-2,jasper-reports,outputstream,zipoutputstream

I figured out what was, I was setting the contentLenght of the response with bytes.length size, but it should be bytes.length * Scale.getPeriodScales(this.startDate, this.endDate).size()

Multiple Subreports in Main Report using same datasource

jasper-reports,jaspersoft-studio

The Problem was with trying to use the same datasource for multiple subreports. The datasource gets exhausted for the first subreport and so no data is available for the subsequent sub reports. Solution : You have to rewind the datasource using JRRewindableDataSource Thanks to lucianc Community answer Summarizing on the...

A XML related exception occurred while compiling the JasperReport

java,maven,jasper-reports

I just figured out the issue after trying few days. Initially the issue was that i have added the dependencies which jasperreports depends on one by one manually into my pom which I don't have to do. Then there have been conflicts. Only jasperreports and groovy dependencies are enough. If...

SQL if statement with more conditions

sql,jasper-reports,jaspersoft-studio

Here is an example of how you would go about doing this: <image> <reportElement x="0" y="1" width="100" height="37"/> <imageExpression> <![CDATA[($F{status} == 3) ? $P{IMG_DIR} + "not_attempted.png" : (($F{status} == 2) ? $P{IMG_DIR} + "scorm_completed.png" : (($F{status} == 1 || $F{status} == 0) ? $P{IMG_DIR} + "scorm_incompleted.png" : null))]]> </imageExpression> </image>...

IReport Java Long subtraction incorrect (possibly overflow)

java,jasper-reports,ireport

I have tried this and nothing wrong with the iReport. Here is my JRXML file- <?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="report1" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20"...

Cannot cast from BigDecimal to String in jasper (weird error //$JR_EXPR_ID=18$)

jasper-reports,ireport

You have a field eg $F{ID} with field class=java.math.BigDecimal.As you want to use this field as a string as well as decimal; You can create two variables variable1 with variable Class=java.math.BigDecimal with Variable Expression as $F{ID} and create another variable variable2 with variable Class=java.lang.String with Variable Expression as $F{ID}.toPlainString()...

Conditionally select a list node in iReport?

xpath,jasper-reports

Yes, you should use XPath. Try this one: /list/customer[type='business'] ...

Jasperreports Textbox shouldn't split across page

jasper-reports

Fixed by setting split type to "Immediate" and changed the print order to "horizontal"

Jasper server rest service returns unauthorized

c#,jasper-reports,httpclient,jasperserver

You could use a CookieContainer to hold the session cookie, rather than setting a header. See How do I set a cookie on HttpClient's HttpRequestMessage for an example....

Font embedded in main jasperreport but not in subreport when exporting to PDF

java,fonts,jasper-reports,ireport,jaspersoft-studio

I managed to solve this problem; Here is what I did: Backup your project somewhere safe. Remove project from jasper. Remove previously installed fonts (Window -> preferences -> Jasper Studio -> fonts) Delete JasperSoft Studio Reinstall jasperSoftStudio open previously backed up project again in JasperSoft Studio Rebuild project Change textfields...

In Jaspersoft Studio, how do I use the DATEFORMAT() function?

jasper-reports,jaspersoft-studio

you can find the source code for the DateTime functions directly in JR repository: https://sourceforge.net/p/jasperreports/code/ci/master/tree/jasperreports/demo/samples/functions/src/net/sf/jasperreports/functions/standard/DateTimeFunctions.java As you can see the code is fairly simple and relies on the Joda Time library. Therefore the second parameter you are trying to enter is a String, while the first one is a...

Jasper compilation error java.lang.NoClassDefFoundError it/businesslogic/ireport/IReportScriptlet

java,jasper-reports,ireport

I included iReport-1.3.1.jar file and issue vanished

set content header name in response in java

java,jasper-reports

Check public JRViewer - you can create JRViewer(java.lang.String fileName) or setParameter - reference code String fname= "fileName.jasper"; JasperPrint print = JasperFillManager.fillReport(yourDir+"jasper/"+fname); exporter.setParameter(JRExporterParameter.OUTPUT_FILE, fname); porterParameter.OUTPUT_FILE_NAME, nfl); exporter.exportReport(); ...

Report design not valid. Field not found Jasper Reports

java,jasper-reports

Fount out the issue. name attribute should defined inside the subdataset. Otherwise it wont work <subDataset name="dataset1" uuid="09015d96-ad5a-4fed-aa9e-19d25e02e205"> <field name="name" class="java.lang.String"/> </subDataset> ...

JSON Array in ireport

java,json,jasper-reports,ireport

I have found a solution, in ireport during json datasource creation i have mentioned "Use the report JSON expression when filling the report" This solved the problem....

Jasper Report — Resource not found

php,jasper-reports,jasperserver,jaspersoft-studio

Hmm the rest endpoint to "run" a report is js/rest_v2/?path to report?.html Unless your report is in the root of your organization, then you need a path. Check out this (line 20): https://github.com/jasonhuber/Jaspersoft_InputControlsFromCSV/blob/master/index.html#L20 and check in the web services guide page 71......

How to get last date of the month in Jasper Report date parameter input control?

jasper-reports,ireport

Have a look to this blog - Date calculation in iReport. I have tried this and it is working fine. Here is my jasper file- <?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="report1" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail"...

How to pass in-memory JasperReport Design to Spring View

java,spring,spring-mvc,jasper-reports,spring-boot

I'm not really sure if this is what you're looking for, but here's how I do it. (I have changed names of things to make them generic, hopefully it still compiles/works) @RequestMapping(value="/report", params = {"objectid"}, method = { RequestMethod.GET }) public void getReport(HttpServletResponse response, @RequestParam(value = "objectid") long objectid){ Object...

JAVA_HOME not defined correctly

java,jasper-reports,jasperserver,java-home

You say the file /opt/jasperreports-server-cp-5.0.0/apache-tomcat/java/bin/java exists, right ? Can you execute it ? Can it execute standard jar file ?...

Using parallelism to generate a large number of PDF files in UNIX

java,unix,jasper-reports

Unfortunately you cannot use less memory and use multithreading to render different PDFs, each thread would allocate memory to work on its PDF, memory usage would be linear to the number of threads. It's a completely different story if you can work on the same PDF(same data) with multiple threads,...

How to add Multiple Variables in THEN clause When using WHEN THEN in Select statement

mysql,sql,jasper-reports,ireport,case-when

Change your logic to simple boolean comparisons: WHERE ( $P{status} is not null AND STATUS IN ($P{status}, ' ') ) OR ( $P{status} is null AND STATUS IN ('V', 'R') ) ...

How to use object of a class which contain object of another class as datasource in jasper report?

jasper-reports,jasperserver,jaspersoft-studio

You can try something like this: Declare only the instances variables of the Person class as jasper reports fields: one field will be "name" of type java.lang.String and another field will be "address" of type your.package.Address (that's it). Then, if you want to print address specific information in the report,...

Updated JasperReports jasperserver to 6.1, but can't start it

jasper-reports,jasperserver

I looked back at the installation log, and indeed there was a problem with the installation. I wound up starting fresh an ran the installation, not the upgrade, and it worked.

download jasper report to a specific location in the server

java,servlets,jasper-reports

You can use JasperExportManager to save the generated pdf to a specific location in server JasperExportManager.exportReportToPdfFile(jasperPrint, exportPath); eg: String exportDir = System.getProperty("jboss.server.config.dir") +"/jasperreport/export"; String exportPath = exportDir + "/reportName.pdf"; JasperReport jasperReport = CompileManager.compileReport(jrxmlFilePath, mainReportName); JasperPrint jasperPrint =JasperFillManager.fillReport(jasperReport, parameters, jsonDataSource);...

Passing parameters to `In` clause

sql,jasper-reports,jaspersoft-studio

I think the right solution will be: SELECT * FROM `medication` WHERE $X{IN,idMeidication,parameter_name} without $P!{} In this way i use it in my reports....

net.sf.jasperreports.engine.JRRuntimeException: Category series name is null

java,jasper-reports

The problem is the input data. You are using the method: fillReport(JasperReport jasperReport, java.util.Map<java.lang.String,java.lang.Object> parameters, JRDataSource dataSource) However you have neither parameters nor a datasource specified. JasperPrint jasperPrint = JasperFillManager.fillReport(jasper.getPath(),new HashMap(), new JREmptyDataSource()); I think your report contains more than just a label. This error appears when you try to...

unsuported class version error ireport java maven vraptor

java,maven,jasper-reports,ireport,vraptor

Class br.com.bup.domain.ContaBancaria in your classpath is compiled with jdk 7 and your development machine is using below jdk 7. Please upgrade your JDK.

java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.setColumnWidth(II)V

java,jasper-reports

If the code compiles but you get this error at runtime, it can mean only one thing: you're compiling and running with different library versions. The version you compiled against has this method while the one you ran with doesn't. It could have also happened that you have multiple versions...

Creating XML for Jasper Reports

java,xml,jasper-reports

Using @ChristofferPass's suggestion of JAXB (Thank you!) public static void main(String[] args) { try { ListBeans lb = new ListBeans(); lb.add(new MyBean(1)); lb.add(new MyBean(2)); JAXBContext jaxbContext = JAXBContext.newInstance(ListBeans.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(lb, new File("c:\\temp\\mybean.xml")); } catch (Exception e) { } ; } @XmlRootElement(name = "ROOT") public static...

Jasper Reports Parse XML column-blob

java,xml,postgresql,jasper-reports

You could do this directly in postgresql during the select. PostgreSql has an XML Type and various XML functions. If you take a look at those functions, you'll see the xpath function which can be used to extract data from XML types during a select statement. For a reference to...