Click to Rate and Give Feedback

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
Other versions are also available for the following:
SQL Server 2008 Books Online (June 2009)
Sum (MDX)

Returns the sum of a numeric expression evaluated over a specified set.

Sum( Set_Expression [ , Numeric_Expression ] )
Set_Expression

A valid Multidimensional Expressions (MDX) set expression.

Numeric_Expression

A valid numeric expression that is typically a Multidimensional Expressions (MDX) expression of cell coordinates that return a number.

If a numeric expression is specified, the specified numeric expression is evaluated across the set and then summed. If a numeric expression is not specified, the specified set is evaluated in the current context of the members of the set and then summed. If the SUM function is applied to a non-numeric expression, the results are undefined.

ms145484.note(en-us,SQL.100).gifNote:
Analysis Services ignores nulls when calculating the sum of a set of numbers.

Examples

The following example returns the sum of Reseller Sales Amounts for all members of the Product.Category attribute hierarchy for calendar years 2001 and 2002.

WITH MEMBER Measures.x AS SUM
   ( { [Date].[Calendar Year].&[2001]
         , [Date].[Calendar Year].&[2002] }
      , [Measures].[Reseller Sales Amount]
    )
SELECT Measures.x ON 0
,[Product].[Category].Members ON 1
FROM [Adventure Works]

The following example returns the sum of the month-to-date freight costs for Internet sales for the month of July, 2002 through the 20th day of July.

WITH MEMBER Measures.x AS SUM 
   (
      MTD([Date].[Calendar].[Date].[July 20, 2002])
     , [Measures].[Internet Freight Cost]
     )
SELECT Measures.x ON 0
FROM [Adventure Works]

The following example uses the WITH MEMBER keyword and the SUM function to define a calculated member in the Measures dimension that contains the sum of the Reseller Sales Amount measure for the Canada and United States members of the Country attribute hierarchy in the Geography dimension.

WITH MEMBER Measures.NorthAmerica AS SUM 
      (
         {[Geography].[Country].&[Canada]
            , [Geography].[Country].&[United States]}
       ,[Measures].[Reseller Sales Amount]
      )
SELECT {[Measures].[NorthAmerica]} ON 0,
[Product].[Category].members ON 1
FROM [Adventure Works]
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker