One of our site owners recently ran into a situation in which he was trying to create a SharePoint view that would provide a sum of all values contained within a calculated field, but was not able to do so via the simple configuration process. By "simple configuration" process, I'm referring to the typical way that you would provide a sum on a standard number or currency field which would be to place your view in edit mode, scroll down to and then expand the
Totals group, locate your field, select the "Sum" operation listed in the drop down control, and save the change to your view. Unfortunately, this isn't possible for calculated fields due to the fact that calculated fields don't show up under the
Totals group. With this in mind, a few possible solutions that would provide the requested functionality are listed as follows:
- Use a Content Query Web Part to host the XSLT code that would generate the desired view
- Use SharePoint Designer to modify the XSLT code of the view directly. In SharePoint 2007, you would do this by inserting a Data View web part and modifying the XLST of that web part.
- Change the calculated field to a regular number or currency field, add a workflow to the list that would perform the calculations previously associated with the calculated field, and place a sum operation on the field
After a discussion with the user about the requirements for this effort as well as the various options available, we came to the conclusion that it would be possible to use a simple, one-time solution to meet the needs of his effort. In light of this, we chose the workflow option and decided to add our workflow to the list using SharePoint Designer. If you're interested in this solution, here are the steps we took to make this happen:
Replace the calculated field with a standard number or currency field
- Using your browser, open the site and navigate to the list to be modified
- Under List Tools, click on the List tab
- Click on List Settings
- Under Columns, locate your calculated field and click on it's link
- Record the formula for your calculation
- Click Delete to remove the column
- Click on Create column
- For Column name:, enter the name of the original calculated field that you just deleted
- Select either the Number or Currency radio button depending on which you require
- Click OK
Create and publish the calculation workflow using SharePoint Designer
- Open Microsoft SharePoint Designer 2010
- Click Open Site
- For Site Name:, enter the URL of the site your list is contained under
- Click Open
- Under Navigation, click on Lists and Libraries
- Click on the list you wish to perform the calculations on
- Under Workflows, click on the New... icon
- Add an appropriate Title and Description for you workflow
- Click OK
- Once the Workflow Designer appears, click on the Action button
- Under Core Actions, select Do Calculation
- Click on the first value link
- Click on the function icon
- For Data source:, select Current Item
- For Field from source:, select your first field that is part of the calculation
- Click OK
- Click on the plus link and choose the appropriate option for your calculation
- Click on the second value link
- Click on the function icon
- For Data source:, select Current Item
- For Field from source:, select your second field that is part of the calculation
- Click OK
- Click on the Action button
- Scroll down to List Actions and click on Set Field in Current Item
- Click on the field link and select the field you just created previously that replaced the original, calculated field
- Click on the value link
- Click on the function icon
- For Data source:, select Workflow Variables and Parameters
- For Field from source:, select the Variable: calc item
- Click OK
- If needed, continue adding calculation steps until the workflow is complete
- Click the Save button
- Under Navigation, click on Workflows
- Click on the link associated with your newly created workflow
- Under Start Options, remove the check from the Allow this workflow to be manually started option
- Place a check in both the Start workflow automatically when an item is created and Start workflow automatically when an item is changed options
- Click the Save button
- Click the Publish button
Update your view to provide a sum on the new field
- Using your browser, open the site and navigate to the list to be modified
- Under List Tools, click on the List tab
- Click on List Settings
- Under Views, locate your view and click on it's link
- Scroll down to and then expand the Totals group
- Locate your new field and select the "Sum" operation listed in the drop down control
- Click Save
With these steps complete, the new "calculated" field will be updated by the workflow every time a list item is created or modified. NOTE: Users will be able to enter values into the "calculated" field; however, the workflow will ultimately override this value when the items is created or saved. At this point, you will now have a "sum" operation on your "calculated" field.