Microsoft KB Archive/248219

From BetaArchive Wiki
Knowledge Base


OFF2000: How to Create a New Calculated Member for the Current PivotTable Session

Article ID: 248219

Article Last Modified on 10/11/2006



APPLIES TO

  • Microsoft Office PivotTable Component 9.0, run time



This article was previously published under Q248219

SUMMARY

The Microsoft Office PivotTable Component that is included with Microsoft Office 2000 Service Release 1 (SR-1) introduces the ability to create a new calculated member when your data source is an Online Analytical Processing (OLAP) server or cube. This article contains sample VB Script code that illustrates how to create a new calculated member for use with the current session of the PivotTable list.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following example illustrates how to add a calculated member for use with your PivotTable list.

<HTML>
<BODY ONLOAD = "Setup_PT()">

<OBJECT ID="PivotControl" 
        CLASSID="CLSID:0002E520-0000-0000-C000-000000000046"
        style="HEIGHT: 500px; WIDTH: 500px"> 
</OBJECT>

<SCRIPT language=VBScript>
 
    Sub Setup_PT()

       ' Specify the information necessary to connect to the OLAP data 
       ' source. Replace OLAP_SERVER with the name of your OLAP server or 
       ' the path to your OLAP cube file.
       strConn = "Provider=MSOLAP.1;Persist Security Info=False;User" & _
                 "ID=sa;Data source=OLAP_SERVER;"Initial Catalog=FoodMart"
 
       ' Connect the PivotTable list to the OLAP data source.
       PivotControl.ConnectionString = strConn
       PivotControl.DataMember = "Sales"
 
       set conn = PivotControl.Connection
       Set view = PivotControl.ActiveView
      
       ' Pass the statement that creates the new calculated member through
       ' the Connection object.
       conn.execute "Create member [Sales].[measures].[Profit per Unit]" _
                  & "as '[measures].[profit] / [measures].[unit sales]'"
      
      
       ' The following two lines of code are necessary to add the new 
       ' calculated member to the PivotTable list.  
       PivotControl.Refresh
       set data=PivotControl.ActiveData
       
       ' Add the appropriate data to the PivotTable list.
       view.RowAxis.InsertFieldSet view.FieldSets("Promotions")
       view.DataAxis.InsertTotal view.Totals("Store Sales") 
       view.DataAxis.InsertTotal view.Totals("Profit")

       ' Add the new calculated member to the PivotTable list.
       view.DataAxis.InsertTotal view.Totals("Profit per Unit")
    End Sub
</SCRIPT>

</BODY>
</HTML>
                

REFERENCES

For more information about Online Analytical Processing (OLAP), click Microsoft Excel Help on the Help menu, type OLAP in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.



Additional query words: OFF2000 pivotlist tensor mdx olap

Keywords: kbfix kbhowto KB248219