This question already has answers here:
Format a BigDecimal as String with max 2 decimal digits, removing 0 on decimal part
(5 answers)
Java format BigDecimal numbers with comma and 2 decimal place
(2 answers)
Closed 2 years ago.
I am working on a MySql backed Jasper report. I have 5 BigDecimal Variables in my report. This report calculates the yearly charge of multiple services .I need to add the first 4 and the subtract the last one. Some of these these variables can potentially house fairly large values ( 8 figures ). I donot know how to do calculations is BigDecimal. I have tried making a Double variable and doing the following
Double.valueOf($V{enc}.doubleValue() + $V{Bed}.doubleValue()+$V{Diet}.doubleValue() + $V{Investigation}.doubleValue() - $V{ref}.doubleValue())
The report does not give any error but leads to 7.269307848E9 as shown below:
254350, 14589, 8122, 3708, 0 7.269307848E9
( these are the values of the original variables except the last one which is the result of the calculation )
While searching for the solution, I did come across the following:
($V{enc}.ADD($V{Bed})).toString()
I am not sure how I can apply it in my case. This can add only two values.
I need to have a whole value, not decimal like above. By the way, I use iReport 1.2.0, which is a requirement for generating the report.
Related
This question already has answers here:
How can I increment a variable with value of another variable in JasperReports?
(3 answers)
How to sum all values in a column in Jaspersoft iReport Designer?
(2 answers)
Closed 2 years ago.
I want to make a Jasper Report that desplays a field and at the end it sums all the numbers from it. The problem is that the column is java.lang.String because it has dashes(-) and numbers.
For example I have the column in the picture. I create a variable that sums every number of the column. For every dash it should add a zero. So for the example column the result should be sum=282.
I tried the following.
IF(Boolean.valueOf($F{Column}).equals("-") ? $V{Sum} = $V{Sum } + 0 : $V{Sum}= $V{Sum} + Long.parseLong($F{Column}))
But it gives an error "The left-hand side of an assignement must be a variable"
Does anyone have any ideas on how to do it correctly? Thank you!
This question already has answers here:
Calculate average using Spark Scala
(4 answers)
Closed 2 years ago.
I am new to Spark and I couldn't find enough information to understand some things in Spark. I am trying to write a pseudocode in scala (like these examples http://spark.apache.org/examples.html)
A file with data is given. Each line has some data: number, course name, credits, and mark.
123 Programming_1 10 75
123 History 5 80
I am trying to compute the average of each student (number). Average is the sum of every course credits*Mark a student had took
divided by the sum of every course credits the student took. Ignoring any line that has mark==NULL. Suppose that I have a function parseData(line) which makes a line with strings to record with 4 member : number, coursename, credits, mark.
What I tried until now
data=spark.textFile(“hdfs://…”)
line=data.filter(mark=> mark != null)
line= line.map(line => parseData(line))
data = parallelize(List(line))
groupkey= data.groupByKey()
((a,b,c)=>(a, sum(mul(b,c))/ sum(b))
But I don't know how to read the specific values and use them to produce the average for each student. Is it possible to use array?
Once you filter and get the dataframe, you could use something like this:
df.withColumn("product",col("credits")*col("marks"))
.groupBy(col("student"))
.agg(sum("credits").as("sumCredits"),sum("product").as("sumProduct"))
.withColumn("average",col("sumProduct")/col("sumCredits"))
Hope this helps!!
This question already has answers here:
How to sum all values in a column in Jaspersoft iReport Designer?
(2 answers)
Closed 4 years ago.
I need to do a high precision sum in a footer of JasperReports's report. Usually if you have a Double field you can drag and drop the field in the footer group and a popup window will be show displaying what kind of calculation do you what, sum for example. But if you have a BigDecimal field this popup window does not show.
So how can I sum BigDecimal Field in a (footer) group of report?
Just go the manual way.
Add a variable
Give it a meaningful name
Change the type to java.math.BigDecimal
Set the Calculation to the type you need, Sum in your example
Add the variable to a text field or add it with drag and drop to the report
Set your desired Evaluation time
I am trying to create a crystal report chart that counts the number of opened and closed tickets of each month.
Example they opened 10 tickets but 15 were close (7 from the same month 8 from other months).
When I try to generate the report I can get either the open or the closed working. I know the problem is with the grouping (if grouped by the submitted date the submitted date is right but the closed is wrong because of ones from other months and vis-a-versa).
I have tried overlapping the reports but the problem with that is the auto scale could be different for the reports and fixed scaling is not an option.
Because the data is filtered to return all rows with a submitted date or a closed date is greater than one year ago. I use a sum to count the records
example:
if submitted > 1 year ago
1
else
0
same for closed
For the display I need a bar chart where the two groups are sorted by the month. One bar for the ones opened in that month and one bar for the closed of that month.
Similar situation but I can't modify the sql.
One record in multiple Groups within Crystal Reports XI
I'll offer my solution based on years of wrestling with Crystal.
Do your data processing in the database (stored procedures) or core application (C# or whatever), then hand off a simple table or two to Crystal.
This makes your reports lightweight and easy to maintain (or move to another reporting tool later on) and puts the "guts" of your logic in plain code that can be managed in source control.
I'm sure you could get it to work in Crystal, but next month you will forget how it works and your coworkers will be even worse off. Let Crystal do basic formatting and render a pretty report, but do the hardcore data processing elsewhere.
Spend an hour feeding Crystal simple data rather than spending an hour configuring 5-level-deep options in the Crystal designer.
This question already has answers here:
How to show/hide a column at runtime?
(8 answers)
Closed 5 years ago.
I need to create a report where the number of columns changes based on the data being passed to iReport just like with a subreport. Is there a way to do this?
I agree with Ischin's answer, but I will elaborate.
The Crosstab Report will allow you to have dynamic columns because it allows you to pivot your data. You can select one or more fields to group by to create the columns. The values of the groups become the labels for the columns and then you must use aggregate functions for the values in the report called Measures (e.g., sum or count). If you select more than one field, you will have multiple levels of columns. When you design the report, you pick the size of the columns--they must all have the same size.
JasperReports is a product designed for creating something that will print on a piece of paper consistently, like a PDF. iReport as of at least version 5.1.0, does not have any other way to truly dynamically create columns. You could write in logic to show or hide columns based on parameters, but this would be very tedious and does not fit in with what JasperReports is designed for. It would be very difficult, for example, to allow the user running the report to select parameters that allow the user to control which columns are in the report and the positions of the columns.