Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

calcul the sum

hello;
i have more than tow tables in a data base (Access). it have the same structure.
I would like calculate the sum total of a columun ("net" for example) for all tables and put the result in a variable.
Can you please help me
Labels (2)
14 Replies
Anonymous
Not applicable
Author

Hi,
looks like the tJava is executed before the tJavaRow. To get the sum at all add remove tJava from your stream and add it with an OnSubjobOk. This should work.
Bye
Volker
Anonymous
Not applicable
Author

Hi Volker;
thank you for your help.I tr it but it dosn't work.
Could you please post a screen shot .
Thank you
Anonymous
Not applicable
Author

Hi,
sorry for the late post. Last week half of my family was down with the flu.

So first I think I get the reason for the problem. I run into the self error at creating an example. It seems that you must define a initial value for your context variable. Talend is using Double and not the native type double. So the += operator throws a NullPointerException.
Anyway here is my solution:
Code in tJavaRow
output_row.orderId = input_row.orderId;
output_row.orderText = input_row.orderText;
context.sum+= input_row.orderId;

Code in tJava
System.out.println("The sum of all order ids is: " + context.sum);

And the output of the job:
1|Mr. Jones first order
2|Mr. Jones second order
3|The third order of Mr. Jones
6|Mrs. Tompson first ordr
7|Mrs. Tompson second order
8|Mrs. Tompson order number third
18|Mrs. Jones only one order
19|Mr. Albert only one order
20|Mrs. Albert first order
21|Mrs. Albert second order
22|Mrs. Albert third order
The sum of all order ids is: 127.0

The jobs selects for some customer orders from a database and calculates the sum of the customerId.
Bye
Volker
Anonymous
Not applicable
Author

Hi Volker;
Sorry for my late. I have a problem in my Internet Connexion.
I hope in good health and your family too.
Thank you for your anser.It was a good solution.
Problem resolved.
Thank you
Anonymous
Not applicable
Author

Thanks. This helped me also.