Microsoft KB Archive/301637

= INF: How to Calculate the Cumulative Value of a Measure =

Article ID: 301637

Article Last Modified on 2/20/2007

-

APPLIES TO


 * Microsoft SQL Server OLAP Services
 * Microsoft SQL Server 2000 Analysis Services

-



This article was previously published under Q301637



SUMMARY
In a number of applications and business reports you want to obtain or return cumulative values for one or more measures. This article illustrates the use of the SUM, PeriodsToDate, YTD, QTD, and ITEM functions to return cumulative values over a period of time.



MORE INFORMATION
One approach to calculating cumulative values for a measure during all time requires the addition of an (All) level to the time dimension:  Open Analysis Manager, and then open the FoodMart 2000 database. Edit the Time dimension and add an All level. Process the Time dimension and the Sales cube. Adding the All level results in members being summed automatically. Open the MDX sample application, and then select the FoodMart 2000 sample database.  Test the validity of the formula that you will be using for a calculated measure by executing this Multidimensional Expressions (MDX) query: WITH MEMBER MEASURES.[Sales To Date] AS 'Sum(PeriodsToDate([Time].[(All)]), [Measures].[Unit Sales])' SELECT {[Measures].[Unit Sales],[Measures].[Sales To Date]} ON COLUMNS, [Time].[Month].Members ON ROWS FROM [Sales]  Note the values that display in the data grid.

 Close the MDX sample application.</li> Edit the Time dimension and remove the All level. Re-process the Time dimension and the Sales cube.</li></ol>

An alternate approach to calculating cumulative values for a measure requires use of the ITEM function with the colon operator to sum over a range of times. <ol> Open the MDX sample application, and then select the FoodMart 2000 database.</li>  Test the validity of the formulas that you are going to use to calculate measures by executing this MDX query: WITH MEMBER MEASURES.[Sales To Date] as 'SUM({[Time].CurrentMember.Level.Members}.Item(0):Time.CurrentMember,[Measures].[Unit Sales])' -- Use the ITEM function to return the first member then sum to the currentmember MEMBER MEASURES.[Sales Year To Date] AS 'SUM(YTD,[Measures].[Unit Sales])' -- Use the YTD function to sum for Year To Date MEMBER MEASURES.[Sales Quarter To Date] as 'SUM(QTD,[Measures].[Unit Sales])' -- Use the QTD function to sum for Quarter To Date SELECT {[Measures].[Unit Sales],[Measures].[Sales To Date],[Measures].[Sales Year To Date],[Measures].[Sales Quarter To Date]} ON COLUMNS, [Time].[Month].Members ON ROWS FROM [Sales] </li> Close the MDX sample application.</li> Edit the Time dimension and change the All level to NO. Re-process the dimension and the Sales cube.</li></ol>

Now that you have tested the formulas for the calculated members, you can add the formulas to the Sales cube. <ol> Open the Sales cube for editing.</li>  Add a new calculated member with the following properties: Parent Dimension: Measures Name           : Sales To Date Value          : SUM({[Time].CurrentMember.Level.Members}.Item(0):Time.CurrentMember,[Measures].[Unit Sales]) Format String  : STANDARD Click OK to save the calculated member. This calculated member returns the value of the Unit Sales measure since the beginning of time. </li>  Add a new calculated member with the following properties: Parent Dimension: Measures Name           : Sales Year To Date Value          : SUM(YTD,[Measures].[Unit Sales]) Format String  : STANDARD Click OK to save the calculated member. This calculated member returns the value of the Unit Sales measure for the year to date. </li>  Click OK to save the calculated member. This calculated member returns the value of the Unit Sales measure for the quarter to date. Parent Dimension: Measures Name           : Sales Quarter To Date Value          : SUM(QTD,[Measures].[Unit Sales]) Format String  : STANDARD </li> Browse the cube data and note the values that display in the newly added calculated members. </li></ol>

Additional query words: SUM PERIODSTODATE YTD QTD MTD ITEM COLON BIHowto OLAP

Keywords: kbinfo KB301637

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.