locked
Dataview webpart - calculating average from multiple group averages RRS feed

  • Question

  • I have a list called ProjectTasks. In that list, I have columns called Projects, ProjectType, and PercentComplete.

    I created a dataview webpart for this list that groups it by Projects and ProjectType.  For the header of the ProjectType group, I was able to get the average of PercentComplete for each category. Now, I'm having trouble getting the average of those averages in the each category in the Projects group.

    Here's a visual...

    Project1  Average: ? (i.e (90+60+25)/3 - where 3 is not constant. There could be a new added item with a new project type)
       -ProjectType1  Average: 90%
             Item1            100% Complete
             Item2             80% Complete
       -ProjectType2  Average: 60%
             Item3            100% Complete
             Item4              20% Complete
       -ProjectType3  Average:  25%
             Item5             30% Complete
             Item6             20% Complete

    Here's a part of my code.  I just copied what I think is relevant in regards to my question.

    <xsl:call-template name="dvt_1.groupheader0">
      <xsl:with-param name="fieldtitle">Project</xsl:with-param>
      <xsl:with-param name="fieldname">Project</xsl:with-param>
      <xsl:with-param name="fieldvalue" select="$groupheader0" />
      <xsl:with-param name="fieldtype" select="'Lookup'" />
      <xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((@Project)=$groupheader0 or ((not(@Project) or @Project='') and $groupheader0=' '))]" />
      <xsl:with-param name="groupid" select="'0'" />
      <xsl:with-param name="displaystyle" select="'auto'" />
      <xsl:with-param name="imagesrc" select="'/_layouts/images/minus.gif'" />
      <xsl:with-param name="alttext" select="'collapse'" />
      <xsl:with-param name="altname" select="'expand'" />
      <xsl:with-param name="hidedetail" select="false()" />
      <xsl:with-param name="showheader" select="true()" />
      <xsl:with-param name="showheadercolumn" select="false()" />
    </xsl:call-template>
    
    <xsl:call-template name="dvt_1.groupheader1">
      <xsl:with-param name="fieldtitle">ProjectType</xsl:with-param>
      <xsl:with-param name="fieldname">ProjectType</xsl:with-param>
      <xsl:with-param name="averagetitle">Average</xsl:with-param>				
      <xsl:with-param name="fieldvalue" select="$groupheader1" />
      <xsl:with-param name="fieldtype" select="'Lookup'" />				
      <xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((@ProjectType)=$groupheader1 or ((not(@ProjectType) or @ProjectType='') and $groupheader1=' '))]" />
      <xsl:with-param name="groupid" select="'1'" />
      <xsl:with-param name="displaystyle" select="'auto'" />
      <xsl:with-param name="imagesrc" select="'/_layouts/images/plus.gif'" />
      <xsl:with-param name="alttext" select="'expand'" />
      <xsl:with-param name="altname" select="'collapse'" />
      <xsl:with-param name="hidedetail" select="false()" />
      <xsl:with-param name="showheader" select="true()" />
      <xsl:with-param name="showheadercolumn" select="false()" />
    </xsl:call-template>
    
    
    
    <xsl:template name="dvt_1.groupheader0">
      <xsl:param name="fieldtitle" />
      <xsl:param name="fieldname" />
      <xsl:param name="fieldvalue" />
      <xsl:param name="fieldtype" />
      <xsl:param name="nodeset" />
      <xsl:param name="groupid" />
      <xsl:param name="displaystyle" />
      <xsl:param name="imagesrc" />
      <xsl:param name="alttext" />
      <xsl:param name="altname" />
      <xsl:param name="hidedetail" />
      <xsl:param name="showheader" />
      <xsl:param name="showheadercolumn" />
      <xsl:if test="$showheader" ddwrt:cf_ignore="1">
    
    <xsl:if test="not($hidedetail)" ddwrt:cf_ignore="1">
     <a href="javascript:" onclick="javascript:ExpGroupBy(this);return false;">
     <img src="{$imagesrc}" border="0" alt="{$alttext}" name="{$altname}" /></a>
    </xsl:if>
     <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">&amp;nbsp;</xsl:text>
    <b>
     <xsl:value-of select="$fieldtitle" />
    </b>
    <xsl:if test="$fieldtitle">: </xsl:if>
    <xsl:choose>
      <xsl:when test="$fieldtype='url'">
      <a href="{$fieldvalue}">
       <xsl:value-of select="$fieldvalue" />
      </a>
      </xsl:when>
      <xsl:when test="$fieldtype='user'">
       <xsl:value-of select="$fieldvalue" disable-output-  escaping="yes" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$fieldvalue" />
      </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    					
    <xsl:template name="dvt_1.groupheader1">
      <xsl:param name="fieldtitle" />
      <xsl:param name="averagetitle" />
      <xsl:param name="fieldname" />
      <xsl:param name="fieldvalue"/>
      <xsl:param name="fieldtype" />
      <xsl:param name="nodeset" />
      <xsl:param name="groupid" />
      <xsl:param name="displaystyle" />
      <xsl:param name="imagesrc" />
      <xsl:param name="alttext" />
      <xsl:param name="altname" />
      <xsl:param name="hidedetail" />
      <xsl:param name="showheader" />
      <xsl:param name="showheadercolumn" />
    
    <b>	
      <xsl:value-of select="$fieldtitle" />
    </b>
    <xsl:if test="$fieldtitle">: </xsl:if>
    <xsl:choose>
      <xsl:when test="$fieldtype='url'">
        <a href="{$fieldvalue}">
          <xsl:value-of select="$fieldvalue" />
        </a>
      </xsl:when>
      <xsl:when test="$fieldtype='user'">
       <xsl:value-of select="$fieldvalue" disable-output-escaping="yes" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$fieldvalue" />
      </xsl:otherwise></xsl:choose>			
    
    <!-- projecttype average -->	
    <b>
     <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp;&#160;&#160; </xsl:text>
     <xsl:value-of select="$averagetitle" />
    </b>
    <xsl:if test="$averagetitle">: </xsl:if>
    <xsl:value-of select="format-number(sum($nodeset/@PercentComplete) div count($nodeset/@PercentComplete), &quot;#,##0.0%;-#,##0.0%&quot;)" />
    <!-- end of projecttype average -->
    
    
    

    Please advise.  Thanks.

    Friday, August 3, 2012 4:27 PM