KAPOW

Welcome to the Kapow forum. Here you can get help, use your skills to help others and enjoy hanging out in the company of other Kapow Robot Developers.


How to SUM extracted values

Share

cmorris

Posts : 14
Points : 608
Join date : 2017-05-17

How to SUM extracted values

Post by cmorris on Thu Mar 22, 2018 11:07 pm

Hi,

Does anyone know how to sum up extracted values, so that I would have a total figure in my variable?  I have a CSV file I am looping over, I want to extract each value then come up with the total.  Any ideas welcome, as I am a bit stuck!

Thanks in advance.
avatar
jking

Posts : 57
Points : 1829
Join date : 2014-03-01
Location : USA

Re: How to SUM extracted values

Post by jking on Fri Mar 23, 2018 3:57 am

You will need 2 variables.  One variable for the Sum, and one variable for the Extracted Value.  Note that the variable for the Sum must be Global.
Extract your value from the CSV.  You next step would be an Assign Variable step using an Expression.
Expression value would be SumVariable+ExtractedValue.  Note that the order is critical.
When you Execute the Assign Variable Step, the SumVariable will be the product of the SumVariable + Extracted Value.
Initially the value of the SumVariable will be blank.  SumVariable+ExtractedValue will result in a value of the ExtractedValue.
Extract your next value and add another Assign Variable Step with the same expression SumVariable+ExtractedValue, the SumVariable will now have the product of both of the extracted values.  You can continue this pattern as often as necessary to sum all values.

An alternate method would be to create a Type that contains variables that match your CSV, and then Create a Database Table based on the Type.
Extract each value into the Type and use a StoreInDatabase step.  
Once you have finished looping your CSV, you can add a QueryDatabase step and write an SQL statement to sum the individual values.

cmorris

Posts : 14
Points : 608
Join date : 2017-05-17

Re: How to SUM extracted values

Post by cmorris on Fri Mar 23, 2018 7:31 pm

That's perfect!  Thank you very much for that explanation, exactly what I was  after.
avatar
jking

Posts : 57
Points : 1829
Join date : 2014-03-01
Location : USA

Re: How to SUM extracted values

Post by jking on Fri Mar 23, 2018 7:47 pm

Happy to help.

Sponsored content

Re: How to SUM extracted values

Post by Sponsored content


    Current date/time is Tue Dec 18, 2018 11:10 pm