# Problem with variable sum

Hi,

I'm working with java 8 and jasper studio 6.3.1.

I have 2 types of rows of textfields on different colums like Total Price, Price w/o Taxes, Discounts%, etc. The first type of row has different amount of rows, for each report, and the variables with the price of a product, taking it from the database. And the 2d type of row is just one row with the sum of all the rows of the first type.

For example:
Total Price -   Price w/o Taxes   -   Discounts%
XArticle: 5€     -          4€              -      20%
YArticle:  7€     -          6€              -     15%
Totals:  12€    -         10€

Now, the 2 variables (one for the lines and other for the final total).

i.e: \$V{total_sum_taxes_line}, where the variable values are:

Value Class Name: java.lang.Double
Calculation: No calculation
Expression: \$F{Containers}*\$F{ContainerPrice}*\$F{TAX}
Initial Value Expresion: new Double(0)
Increment type: None
Reset type: Group1 (The group where the field is)

It multiplies the amount of containers for its price and the taxes, giving you 5 (for example).

Now I have other variables for the 2nd type of row, that sums the total prices and gives you 12€.

Theorically, it should be super easy, and this variable is: \$V{Total_Final_Sum}:
Value Class Name: java.lang.Double
Calculation: SUM
Expression: \$V{total_sum_taxes_line}  (The variable for each line)
Initial Value Expresion: new Double(0)
Increment type: None
Reset type: Report (Coz I only want it once, at the end)

Now, I have it exactly like this for different columns, one has the value of each line and the other has the final sum of all the lines, but it works only for some of the columns.

In other colums, it shows random values that are clearly not correct.

I've tried changing the calculation, the initial value, and the reset type, any of those worked.
I also tried changing the expression of the final sum, and instead of putting the lines variable, I tried putting the calculation with the field from the database:
\$F{Containers}*\$F{ContainerPrice}*\$F{TAX}

But it still doesnt work, and I don't know why.

Attachments:
394
Joined: Oct 24 2019 - 1:32am
Last seen: 3 years 7 months ago

Hi Gabriel :')

try step below :
- drag the field to header footer and it will popup a menu, u want to choose summary
- try execute the report, it should show the summary of the data u rendered

else u want to test first? drag any field to any other than detail band in ur report then choose summary.
it should render the total of the field.

else u hv complicated one which the total is based on each group.
in ur case the group is S.L.U, then if u render ex. S.L.A u want the total is based on the data shown in S.L.A group
u might need to change the Reset type.

hope u did well ! - TV

1273
Joined: Jan 30 2019 - 11:02pm
Last seen: 4 months 3 days ago

Hi TV

Thanks for answering, and yep, my name is gabriel, why is it weird?

So, that's what I have at the moment, and that's the way it's supposed to be done (I thought).

The red rows (is one row in jasper) is a variable on a textfield that calculates some values, it works properly.
The blue row has the final variables, and they have the configuration you've said.

It's a variable inside a textfield on the page footer, the "Calculation" property is set as summary, and the "Expression" has the name of the variable they are suppposed to sum. (The one colored in blue has in the expression the variable used in the red row).
It works properly for some columns, as you can check by summing it (for example "Descuento Labor"), but it doesn't for the ones circled in blue.

I've already tried changing the "Reset type" to Report, Page, or Group, but none of those work.
I've also tried summing values from my database coz I cannot understand where the "114,16€" comes from, it doesn't make any sense to me.

Thank you for your answer TV :). I'll try for a little while, if I find the answer I'll put in on here.

Gaby :)

Attachments:
AttachmentSize
23.5 KB
394
Joined: Oct 24 2019 - 1:32am
Last seen: 3 years 7 months ago

hi Gaby,
not weird, its just.. theres someone special similar to ur name :')

anyway XD
sometimes works from scratch did the magic!
delete the variable, just use field. when u drag there, in the popup choose sum option

welp, i did try some cases before telling others the way and it seems fine (including using variable instead of field), but prob not this one :/
no worries, eventually ull get use to it through experiment.
i once stuck on something for 3weeks without a clue lol
hope u did well asap El :D

regards - TV

1273
Joined: Jan 30 2019 - 11:02pm
Last seen: 4 months 3 days ago

Hi TV,
I suppose it's not a common name.But I hope it's special in the good and not the sad way :')

The thing is, when you drag a field into the report and select something from the popup options, actually it's: creating a textField, a variable with the "Calculation" property set as the one you choose, and then inserting the variable into the textfield, automatiaclly.

I don't mind getting stuck on something for too long, as long as I'm really working/learning and going forward.

Thank you for answering and trying to look for the answer with me,
How is it working and why it's not working for me is a mistery (that newbies like me cannot cmoprehend, yet)

Gaby :)

394
Joined: Oct 24 2019 - 1:32am
Last seen: 3 years 7 months ago

Hi Gaby,

Did you ever resolve this? I'm in the same boat where I have a variable displaying a correct number per row in a group, and another variable in the footer of the group set to simply sum the line variable with reset type group. The summary result is wrong and I've literally spent a week going over this and can't find the reason why it's giving a wrong answer. It's not a rounding or missing number, just a significantly different one.

The correct result is -\$50,166 and the missing 3,644 is not related to anything I can find.

Any info on what you ended up doing to resolve this would be very helpful. Thanks in advance.

546
Joined: Jun 21 2018 - 11:07am
Last seen: 1 year 2 months ago
randomness