Lem.mallari's answer is a huge pain if you cannot assume that the amounts on List A never change, since they don't keep track of whether an item has already been added to the amount. It is not possible to process Workflow through a SharePoint list, which means that there is no easy way to calculate the sum or average number of list items.
The correct way to implement this will require some development. Training for SharePoint developers ( 2010 , 2013 ) will actually provide you with most of the path: the event receiver should fire when items are added or changed in lists A and B, which use the SharePoint API to navigate through list A and average values by name, and then update everything (or just touched) elements in list B. Alternatively, you can use JavaScript to display the sum of all the entries in list A that have the same name as the element in list B while all the data is displayed on your page. If you are comfortable using XPath and InfoPath, you can add List A as a secondary data source to List B and select only the applicable items in List A for summarization.
But if we are talking about Workflows, then only the "workflow only" method is used here. This was verified and successfully completed in 2010. Create your own C list with the following columns:
- Title (string, mandatory, forced implementation of unique values)
- TotalItems (integer, required, default value 0)
- Amount (number, decimal places, but you want, mandatory, default 0)
- Medium (calculated, = IF (TotalItems = 0.0, Sum / TotalItems)) (optional)
Replace the Name columns in lists A and B with the search columns pointing to list C. Delete the Amount column in list B, instead include the Sum column as an additional column. Add the following columns to List A and make sure that users cannot modify them directly. This can be limited by creating InfoPath forms or by creating alternative viewing and editing forms.
- Amount Archive (identical to quantity, default 0)
- Amount HasBeenSubmitted (yes / no, default no)
Create a workflow to run every time an item is created or changed in list A. Use these commands (I use the list for readability, it became ugly when formatted as code):
- If current item: amount is not equal to current item: AmountArchive
- Set Variable: Item Count to (Data source: List C; Field from source: TotalItems; Search for list item: Field name; Value: Current item: Name (return field as: Search value (as text))
- Calculate the variable: ItemCount plus 1 (output for the variable: ItemCount)
- Calculate List C: Sum (similar settings as above, be sure to use the Lookup Value (as text), not String!) Minus Current element: AmountArchive (output for variable: SumWithoutValue)
- Compute Variable: SumWithoutValue plus Current Element: Sum (Output to Variable: NewSum)
- If current item: AmountHasBeenSubmitted is None
- Set AmountHasBeenSubmitted for Yes
- Refresh the item in the list C (Set TotalItems to the variable: ItemCount; Set the amount to the variable: NewSum; Find the list item in the same field: Name; Value: Current item: Name (return field as: Search value (as text))
- Else
- Update an item in the C list (do nothing with TotalItems; use the same logic to set Sum to Variable: NewSum)
- Set value to current item: AmountArchive
source share