Question

How to find the sum of an entire column


Badge +4

Hi there, 

I need to find the sum of each the entry in a particular column 

Here is what the column looks like. As of right now, it just returns 996 instead of a  total of all three values. 

 

 


12 replies

Userlevel 5
Badge +14

like just in sharepoint? that should be pretty straight forward. 
 

Here is a list with a few values in a Number Column: 

 

Modify the view by going to the List tab and then by clicking the Modify View button:

 

Then scroll down to the ‘Totals’ area of the view properties dialog: 

 

Expand the Totals section and select “Sum” from the dropdowns for the Number column in question:

 

Don’t forget to SAVE:

 

The column’s sum is now displayed at the top of the column:

 

Badge +4

like just in sharepoint? that should be pretty straight forward. 
 

Here is a list with a few values in a Number Column: 

 

Modify the view by going to the List tab and then by clicking the Modify View button:

 

Then scroll down to the ‘Totals’ area of the view properties dialog: 

 

Expand the Totals section and select “Sum” from the dropdowns for the Number column in question:

 

Don’t forget to SAVE:

 

The column’s sum is now displayed at the top of the column:

 

 

 

Sorry, should’ve specified that this is for use in a workflow. Would this still apply. Thank you so much for this though

Userlevel 5
Badge +14

if it’s for a workflow then I don’t understand the question based off of the small screenshot you provided. Can you please give us more info / more screenshots of what you want or what you have now?

Badge +4

if it’s for a workflow then I don’t understand the question based off of the small screenshot you provided. Can you please give us more info / more screenshots of what you want or what you have now?

 

Sure, We have a workflow that takes information from two Sharepoint Lists and matches them together based on EmployeeID We want to edit the “Total Points Value” to be calculate total “Bucket Total”. The issue is that each EmployeeID can have several Bucket Total Entries (As Pictured above) This is why we need to calculate the total sum of the entries returned for each EmployeeID  and store it as a new variable 

 

Thanks so much! 

 

Userlevel 5
Badge +14

Alright, so you have Multiple Lists with a column called “Bucket Total”, and you want to gather all of the list items across both lists that share a common EmployeeID, and iterating over the items, need to add the Bucket Total value into a Total Points variable? does this describe the situation? 

 

 

Badge +4

Alright, so you have Multiple Lists with a column called “Bucket Total”, and you want to gather all of the list items across both lists that share a common EmployeeID, and iterating over the items, need to add the Bucket Total value into a Total Points variable? does this describe the situation? 

 

 

Partly, “Bucket Total” only exists in one list. In that one list there are several separate entries for “Bucket Total” across each individual EmployeeID. We need to sum those values for each Employee ID.

Userlevel 5
Badge +14

Let’s say I have a list called Rules JS with the following items: 

 

Here is a workflow that will add all of the Bucket Total column values for a given EmployeeID into a variable called TotalPoints:

 

Let’s break it down. First we’ll start with the variables: 

 

For this example I am using a starting variable which will allow me to set the EmployeeID that I want to target.

 

The first action we’ll configure is Query List:

 

The CAML query is pretty straight forward. We’re looking at the Rules JS list, specifically where EmployeeID is equal to the value of the var_targetEmployeeID variable, and returning every value of the Bucket Total column into a Collection variable called var_BucketTotal_Collection. 

 

Here is the raw XML:

<Query>
<Lists>
<List Title="Rules JS" />
</Lists>
<ViewFields>
<FieldRef Name="Bucket_x0020_Total" />
</ViewFields>
<Where>
<Eq>
<FieldRef Name="EmployeeID" />
<Value Type="Text">{WorkflowVariable:var_targetEmployeeID}</Value>
</Eq>
</Where>
</Query>

 

I can confirm that this works by clicking the Run Now button and replacing the variable reference for var_targetEmployeeID with a known good value like “1”:

 

Which returns a collection of values as expected.

 

Now we need to setup our For Each Loop.

To do so is also straight forward. We’ll set the target collection to the var_BucketTotal_Collection variable as it contains all of the [Bucket Total] column values.

 

Next we’ll set the Store Results In to the var_BucketTotal variable, so that as we loop through the values, whichever value we’re on is stored in that variable.

 

Lastly we’ll set an Index to the var_Index variable even though this part is optional. I tend to do it any ways out of habit. 

 

The configured For Each loop should look like this:

 

Lastly we’ll setup a Math Operation inside of the loop:

 

Which will add whatever value is in the var_BucketTotal variable to the var_TotalPoints variables and save that resulting sum back into var_TotalPoints: 

 

Lastly I’ll send an email out to myself to see if it works:

 

 

Now let’s test it
 

 

The resulting email: 

 

Is it true?

it is!

 

 

Let’s try with EmployeeID 2:

Another success. 

 

Let’s try with an ID that doesn’t exist like EmployeeID 5:

 

It fails, but at least it doesn’t error out because it just creates an empty Collection and doesn’t do anything :)

 

 

Hope this helps to clear things up. 

Badge +4

You have been a tremendous help so far! I would love to connect further and send you dinner or something lol.

 

This works perfectly on its own however is giving me trouble when integrated with the existing workflow. 

 

I am getting an error that states “Failed to Query List Data Exception from  HRESULT: 0x80131904

This workflow was working fine before and nothing has changed on the admin side, so I am assuming it is an issue with the way implemented it. I’m attaching screenshots of the entire workflow below.

Start of workflow

 

Userlevel 5
Badge +14

The error you posted involves the Query List action, I would need to see how that’s configured before I could reasonably know what’s happening.

 

Please take a screenshot of the the Query List Settings and how its configured, feel free to block out any sensitive information like URLS or names, but do try to keep as much as possible 

Badge +4

Sure, I am attaching both the first Query List and the second one that you made.

Please keep in mind that PERNR (Or Perner) is the same as Employee ID which we’ve been referring to throughout this conversation. I just called it that for simplicity.

Like stated above, when I test it with any Employee ID using the “Run Now” button it works perfectly fine.

 

 

 

Userlevel 5
Badge +20

Hi @Edmon 

Is your issue now solved?

Badge +4

Hi @Edmon 

Is your issue now solved?

Not yet, we are running the same error message.

Reply