1,804 articles and 14,840 comments as of Tuesday, May 17th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Thursday, March 18, 2010

SharePoint: Displaying Calculated Column SUMS in a View (Screencast)

Author: Laura Rogers, Birmingham, AL
SharePoint 911

Have you ever noticed that in SharePoint views, when selecting to view “Totals”, calculated columns aren’t listed as an option for column totals? In this screencast, Laura Rogers demonstrates this dilemma, and shows how you CAN create a view that displays calculated column totals. This is done by creating a Data View Web Part in SharePoint Designer. Also, if you’ve noticed that calculated columns don’t ever show up in a data view web part, Laura shows the fix for this, too.

EUSP is sponsoring a series of Live Online Workshops, Make the Most of SharePoint Data View Web Parts with Laura Rogers as host. If you need hands-on experience in creating solutions with the data view web part, you will enjoy attending these sessions.

Author: Laura Rogers, Birmingham, AL
SharePoint 911

View all entries in this series: LauraRogers - Data View Web Part Basics»
 

Please Join the Discussion

43 Responses to “SharePoint: Displaying Calculated Column SUMS in a View (Screencast)”
  1. spevilgenius says:

    HS! Nice one Laura!

  2. Greg says:

    Really nice.
    Gonna have to try with calculated column & Christophe Text to HTML script!
    Combined with an expand/ collapse function, that could beinterresting.
    Your screencasts are always a pleasure to follow.
    Greg

  3. George W says:

    Great great great!

  4. Tom says:

    Thanks, Laura, I am in the midldle of doing a project where this info has come in a very timely manner.

  5. Matt B. says:

    This is excellent Laura. Good work and I love the Holiday Inn Express joke =))

    @EUSP: I just noticed a typo in Laura’s name in this sentence:

    EUSP is sponsoring a series of Live Online Workshops, Make the Most of SharePoint Data View Web Parts with Luara Rogers as host

  6. akram says:

    Your tips are small but they make real difference for endusers. Great, Keep it up

  7. darsh says:

    Hi Laura,

    I have a different situation here where I am doing multiplication of the two columns in calculated column and trying to sum calculated column. In that case your solution did not really help. Any idea on how to get sum of calculated column with multiply two columns.

    Thank you

  8. Varma Rudraraju says:

    I have been using another solution to get the Sum of Calculated fields. I have created a new xsl:template that i can reuse

    The way to use is for example

    I can write an article and publish if it needs more explanation on how to use this

    • Varma Rudraraju says:

      The code didn’t appear when i posted, Let me try this

      • <xsl:template name="SumOfCalculatedField">
           <xsl:param name="Rows"/>
           <xsl:param name="FieldName"/>
           <xsl:param name="result" select="0"/>
           <xsl:choose>
             <xsl:when test="$Rows">
               <xsl:variable name="currentValue" select="$Rows[1]/@*[name() = $FieldName]"/>
               <xsl:call-template name="SumOfCalculatedField">
                 <xsl:with-param name="Rows"
                   select="$Rows[position() > 1]"/>
                 <xsl:with-param name="result"
                   select="$result +
                           number(translate(substring-after($currentValue,'$'),',',''))"/>
                 <xsl:with-param name="FieldName" select="$FieldName"/>
               </xsl:call-template>
             </xsl:when>
             <xsl:otherwise><xsl:value-of select="$result"/></xsl:otherwise>
           </xsl:choose>
         </xsl:template>
        
        a sample for using this template would be,
        <xsl:call-template name="SumOfCalculatedField">
              <xsl:with-param name="Rows" select="/dsQueryResponse/Rows/Row"/>
              <xsl:with-param name="FieldName" select="'Total_x0020_Indirect_x0020_Benef'"/>
             </xsl:call-template>
        
  9. Not sure if this might help someone else but you can also do this easily with a workflow. This was the method I used way back as I like to avoid editing pages if I can help it in SharePoint Designer. This way you can just use as many views as you want and can use all out of the box web interface options.

    http://sharepointkb.wordpress.com/2008/07/22/total-calculated-columns-in-sharepoint/

    Great post and methodology for accomplishing the same sort of thing Laura :)
    Richard Harbridge

  10. Gene Perry says:

    You are the greatest Laura!

  11. dale louie says:

    Laura,

    Do you have an example of where you do these totals with grouping? (For example group by department (assuming you have multiple rows per department)

    Thanks

  12. Laura says:

    Dale,
    Take a look at my post here:
    http://sharepoint911.com/blogs/laura/Lists/Posts/Post.aspx?ID=70

    I have a reference in there, to another post that shows how to do it with groups.

  13. Brian says:

    In the column of items that I’m attempting to sum, when there are blank cells, the sum becomes “NaN”. When there are values in each of the cells, no problems. Any ideas?

    Also, is there an easy way to display these totals in a location other than at the base of the list? I’d like to create a table that displays this data so the user doesn’t have to scroll to the bottom of the list.

    Thanks!

  14. Marc says:

    Laura,

    Great post, I needed to accomplish this in a grouped DVWP and was unable to get it to work however I noticed that if you format the calc colums in $format (in the list colum setup) the DVWP will not display the results as you indicated, however if you format the calc colums in a plain # format (again in the list colum setup) then create your DVWP the results will show up.

    Next I follwed your steps for getting the sum of the rows and then changed the format to $ via the chevron in the DVWP and presto it worked.

    Anyone having the NaN or 0 try this out and see what happens.

  15. Dennis says:

    Converting an excel form into SP and I have numerous choice fields whioch I need to sum on the SPlist. any suggestions?

  16. Bay Phillips says:

    Hello,

    While I found your screencast to be very helpful, I was wondering if you knew of a way to sum the calculated columns grouped by a particular user.

    For example, you have a list of various items that each have an user associated with them, as well as a calculated column. We would then create a new view that would group up all of the items by their user and sum up that calculated column.

    I have been looking around and I cannot find anything related to the issue and am quite lost on how to do it. Any help would be greatly appreciated. Thank you.

  17. Stacy says:

    Hi Laura – Thank you for your video. It was an excellent help to me.

    I have successfully created the column sums within my groups for my data view. However, I would like to go one step further and create an overall sum for the entire data view (a total of all the sums).

    I’ve tried copying and modifying the grouping sum code (removing the nodeset code and replacing it with $Rows), but I’m not getting good results.

    Any suggestions would be greatly appreciated.

    Thank you!!

  18. Henry says:

    Cheers Laura!

    I am trying to create a league table for Formula Student at Liverpool at the moment. And ran into a bit of a problem.
    I was just wondering, is it possible to use the calculated values, for examples, the sum of the columns and plug it into another list? Or use it to sort the columns is ascending order?

    Any help or suggestions would be greatly appreciated
    Thanks!

  19. Martin says:

    Hi,

    Thanks for your hard work. I’m trying to do the same in SharePoint 2010. I got to the part where I should insert the sums row but can’t find this option for the XSLTViewWebPart. Can you help?

    Thanks,
    Martin

  20. Laura Rogers says:

    Hi Martin,
    It appears as though Microsoft has removed this in 2010 XSLT list view, because I can’t find it either. :-(

  21. Tom Caruso says:

    Laura,

    This was very helpful considering how much of a novice I am and I still got through it understanding what you were doing. In fact I even spotted a problem with your calculations. Your final calculated sum is the division of one sum by another, but what is really needed here, in most cases, is a sum across rows.

    I’m doing a calculation that is not the same when done as a sum calculation vs. the sum of the row calculations. In this case it is Hours * Rate in each row, and then a sum of the rows that I need. The rates can not be summed and then multiplied by the sum of the hours to get the number I need.

    So what is the formula (or the code) to create a sum across rows in this XSLT code?

    Tom

  22. Martin says:

    Hi Laura,

    Thank you for your earlier response. I found another option that might be helpful to you and your blog readers. When editing the 2010 XSLTListViewWebPart from the ribbon go under the ‘Design’ tab. To the left-most part you should see two check boxes. One of them says ‘Totals Row’. This works similarly to the row you used in the video. Unfortunately my calculations involve dates and I don’t know how to do it in XSLT.

    If you have an idea I’ll be glad to hear it.

    Regards,
    Martin

  23. Rao says:

    You rocks Laura !…..

    Thanks for sharing this cool stuff…

    Rao.

  24. Chris says:

    is this video dead?

  25. Daniele Gelosini says:

    Hi laura,
    I have problem with a column of a doc lib that is a calculated column with this formula:

    =CONCATENATE(”“)

    Thi show a printer icon and print a report in reporting services with parameters, and i made this with the help of path to sharepoint experience.
    The problem is this code is hosted in a data view web part and it doesn’r render the code and give me a bad text result.
    I have moss 2007 and i ask you how can i translate or modify this code to be rendered correctly?
    Thanks in advance
    Daniele

  26. Laura Rogers says:

    Daniele,
    Sorry I don’t know how to do that. Since I don’t know how to do it, I’d go about it another way:
    create a hyperlink field in your list
    create a workflow that constructs the proper hyperlink, and have the workflow write it to that new hyperlink field.

  27. Scott Hunter says:

    Laura maybe you can help me with this. I have a list that I am able to group by Assigned To and then by Project Designation. I am able to get a count for the total number of task assigned to that person by using this code . I am able to get the Total (sum of hours) from all users. I am able to get the sums for all the task (sum of hours) under each of the Project groups under that user. However I am unable to get the sum of all those task that are assigned to that person. I know that there has to be some kind of code that I can use (like the count) to get the sum of the column for each person but I do not know it and can’t seem to find it.

  28. Amin Hussain says:

    Hi Laura,
    i am attempting to create calculated colums, and am using Sharepoint Designer 2010. However, when I select ‘Show column summary’ a just get an empty row appear at the bottom of the web part, with nothing in it. Cannot see ‘count’ in any of the columns, hence am not sure where to edit the formula in the coding.
    Could you maybe help me with this?

    Kind Regards,
    Amin

  29. Laura Rogers says:

    Here’s my screencast on how to create a data view web part versus XSLT list view web part in 2010: http://www.youtube.com/watch?v=r2eODYHp73A

  30. Tom says:

    I have this weird problem and cannot figure this one out.

    Using your design just mdofied for my need, I have two columns that need to be summed up then one is divided by the other then multiplied by 1000000.

    I keep getting different errors no matter how a format it.
    The two columns that are summed.
    Sum Column 1 Works as expected

    Sum Column 2 Works as expected.

    Column 3 which contains the rows for calculation of column 1 divided by column 2 muliplied by 1000000

    So now I need to take the sums of each and do the same column 1 sum divided by column 2 sum multiplied by 1000000 to get the sum to display in column 3 sum cell.

    Make sense, need help terribly.

    but when I try and finish the sum for Column 3 I get errors.
    ((sum($Rows/@Orig_x002e__x0020__x002b__x0020_0)) div (sum(($Rows/@Orig_x002e__x0020__x002b__x0020_))"$#,##0.;(#,##0.)"’)” />

    • Tom says:

      I get expected Token errors, found item errors, invlaid number of arguments,missing expressions none of which make any sense the format should be correct.
      This was the last attempt

      Thanks for any help or direction

  31. Nice Job, loved the hotel joke! I have been looking for something like this, and you can get your totals by groups as long as it is grouped that way.

  32. Nick Frenette says:

    Laura,
    You just saved me! I have been looking everywhere on how to create a column on an external content type list in SharePoint 2010, at least with this process I am now able to create views of the calculations. Laura, have you tried graphing on a formulated column? Since the data is not stored wonder if I will run into problems?

    thanks,
    Nick

  33. Laura Rogers says:

    Graphing? The chart web part can connect to BCS data, which you can try out.

Trackbacks

Check out what others are saying about this post...
  1. SharePoint – Summing Calculated Columns By Groups (DVWP)…

    I had a problem… okay.. okay.. so I have many problems… but let’s focus on one in particular or this…




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!