cancel
Showing results for
Did you mean:
Highlighted
Nintex Newbie

## How to sum multiple line items to another list

I have a list in which I am storing invoices, I want a running total to be submitted to another list. So for instance List B

Oranges - 5

Oranges - 10

Cherry's - 5

Cherry's - 2

Oranges - 3

I want the sum to get updated to List A so

Oranges = 18

Cherry's = 7

I have looked at the other documentation located here  Adding all values that correspond with an employee in one list, then updating a single item with tha... however I am missing something as I cannot get it to work.  If anyone can provide assistance it would be greatly appreciated.

Labels: (2)

• ### Workflow

Tags (3)
7 Replies
Highlighted
Automation Master

## Re: How to sum multiple line items to another list

Hi Ike,

Can you please explain what part is problematic? The thread you link actually describes the general approach quite well so we need to know where exactly you are stuck.

Regards

Philipp

Highlighted
Nintex Newbie

## Re: How to sum multiple line items to another list

• use another for each to walk through approved hours collection and sum each entry up - now you have the total approved hours for each employee (How are we summing this up? Is it a Math Function?  Another Collection?)
• outside the sum hours for each, but still inside the employee for each, update the available pto list with that total (I'm guessing this is an update item to list A but then how do we filter where we update it to?  So the Total Oranges shows up on the Orange Line and the Total Cherry's shows up on the Cherry's line)
Highlighted
Automation Master

## Re: How to sum multiple line items to another list

1. For summing up values of a collection you use a "for each" action. You configure it to run for each item of your collection and store the collection item of each run in a separate variable. Inside the for each loop you can use a "Math operation" action. First you create a new variable called "sum". Then you configure the math operation like ["sum" + current collection item] and store the result in "sum" again. At the end of the loop the "sum" variable should store the sum of all items in your collection.

2. Yes, this is an "update item" action. When you query List B, you will first query for the fruit types and store all available in a collection. You then loop throguh the fruit types collection and query List B again for the hours of each fruit type but now you know what fruit type you are running on at the moment and can use this information as a filter to update list A. And you do the update of List A in the fruit types loop and not in the hours loop.

I admit it's a little abstract, but I'm sure you'll get this to work.

Highlighted
Nintex Newbie

## Re: How to sum multiple line items to another list

Does it matter that I'm using lookups on the list? I.e. the Fruit is the lookup? Also you said "You configure it to run for each item of your collection and store the collection item of each run in a seperate variable" should this variable be the "Sum" that is then used in the math operation?

Highlighted
Nintex Newbie

## Re: How to sum multiple line items to another list

I have a order status in the system now, so on the form selection it’s using a lookup of fruit types from List A

1. Query List B for Fruit & Approved store this in a collection “Fruit”
2. Remove the Duplicates from the Fruit Collection and Store them in new collection “UniqueFruit”
3. Create For Each
1. Target Collection “UniqueFruit”
2. Store Result in new variable
1. Create Variable “TempFruit” Type of Variable is Single Line of Text
3. Query List B
1. Filter off of Status = Approved
2. Filter off of Fruit = TempFruit (Variable)
3. Field = Quantity
4. Store in “RunningQuantity” (collection)
4. Create For Each (Inside of first Create For Each)
1. Target Collection “RunningQuantity”
2. Create “FinalQuantity” variable (number)
3. Store Result in “FinalQuantity”
5. Create Math Operation inside second “For Each”
1. Workflow Date “FinalQuantity” plus List Lookup Current Item “Quantity” Store Result in “FinalQuantity”
6. Outside of the second “For Each” but inside the first “For Each” Update List Item
1. Update List A
2. Where Fruit equals Value (of list B) Fruit
3. Field selection is Quantity equals Workflow Data “FinalQuantity”

I have four lines in List B all same fruit quantity is 5300, 2650, 10600, 5300.  I am getting a calculation of 15900 as my total in List A is this because it’s pulling out duplicate values?  Or not seeing all of the lines? Thoughts?

Highlighted
Nintex Newbie

## Re: How to sum multiple line items to another list

Hi Ike,

Your almost there.  The issue now is that you're using the FinalQuantity variable as both your running total that you are summing up and the result in your for each.  Every iteration of the loop is overwriting your FinalQuantity variable with the next item in the collection and so you only ever have 2 values being added at any time.  Create a new variable for either the For Each result or your Math operation result and you should be good to go

Highlighted
Nintex Newbie

## Re: How to sum multiple line items to another list

Mark,

That worked perfectly!