List view settings - Show SUM and COUNT

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 9 months ago.

  • Author
    Posts
  • #6418

    by simark at 2013-03-06 18:08:50

    Hi "Colleagues"!

    I would like to activate the "Show Totals" function on a custom list. On the GUI it can be achieved by first selecting the "DataSheet view" mode and then clicking on the "Show Totals" button.
    When I switch back to "Standard view" it still shows the SUM results for each number type columns.
    I did not find any SPList property that would activate this function. My guess was the http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.calculationoptions.aspx property but that returned "none" as result for a list that represents the "Show Totals".
    Any ideas?
    #Get the list
    $Web = Get-SPWeb "MySite"
    $List = $Web.Lists.get_Item("MyList")

    #Your code here :) - how to activate the Show Totals for the $List? -

    Thank you for your support!

    Regards,
    Mark

    by AlexBrassington at 2013-03-07 23:52:07

    Yes.

    You're looking in slightly the wrong place. The Sums value is specified on the view object rather than the list itself (which makes sense, you will want ot specify the totals seperate to the list definition so you can have totals in some views but not all). I've created a demo list which has a count on a field called Assistant Name. If you compare the SchemaXML before and after I added the count you can see the following changes:

    Before:

    After:

    Of course that's just encoded XML but it's not the easiest thing to work with. To access the property more directly you can use the following:
    $list.views["Default"].Aggregations
    Which returns the following

    I've been playing about with it and i've seen some success with the following:
    $testAggregation = @"

    "@
    $SPWeb = Get-SPWeb $siteURL
    $list = $SPweb.Lists[$docLibName]
    $view = $list.views["Default"]
    $view.Aggregations = $testAggregation
    $view.AggregationsStatus = "On"
    $view.Update()
    $list.Update()

    The code above seems to work partially, i had to edit the view manually and hit ok (no changes but just click ok on the page) to get the changes to take effect the first time. Also the code to add 'Name' doesn't work on my library for some reason.

    by simark at 2013-03-08 04:33:18

    Hi Alex,

    I have checked out what you have suggested and it works fine. I had to make a minor modification on the following line
    $view = $list.views["Default"]
    The $view had null value. Maybe there is no view named "default" for my document library. I managed to get the default view with the following line
    $view = $list.defaultview
    I have changed the SchemaXML to return SUM, not COUNT so it will sum up the numeric values in the column.
    $testAggregation = ""

    Thank you for the solution!

You must be logged in to reply to this topic.