You can use your favorite social network to register or link an existing account:
Or use your email address to register without a social network:
Sign in with these social networks:
Or enter your username and password
Forgot your password?
Yes, please link my existing account with for quick, secure access.
No, I would like to create a new account with my profile information.
Tips
How-to
News
Videos
Stories
Today's author: Allan Folting, a program manager who works on the Excel team.
I have gotten lots of questions from customers around specific functionality in Microsoft Excel 2007 PivotTables that is missing when connected to Microsoft SQL Server 2005 Analysis Services Service Pack 2 cubes:
I have also gotten lots of requests for the ability to add calculations to OLAP PivotTables using the object model, specifically:
Today I'll discuss these topics and outline current ways and workarounds to address this.
Behaviors in Excel 2007 specific to Analysis Services 2005 Service Pack 2 (SP2) cubes
Let's start with a bit of background information.
With Analysis Services 2005 SP2+, Excel 2007 uses subselects in the MDX queries generated when filtering is applied to a PivotTable.
In the following example of MDX generated by an Excel 2007 PivotTable, the user is filtering a geography hierarchy to only show United States and Australia which is represented by the subselect part of the query (in bold font).
SELECT NON EMPTY Hierarchize({DrilldownLevel({[Customer].[Customer Geography].[All Customers]})}) DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON COLUMNSFROM(
SELECT ({[Customer].[Customer Geography].[Country].&[United States], [Customer].[Customer Geography].[Country].&[Australia]}) ON COLUMNS FROM [Adventure Works]
)WHERE ([Measures].[Internet Sales Amount])CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS
Subselect support in the OLAP server is required in order for the new Label, Date and Value filtering features to be available in Excel 2007 PivotTables. The reason is that the subselect feature is designed for making Analysis Services calculate visual totals while filtering which was also an explicit design goal for Excel 2007 PivotTables.
When multiple filters are applied to different hierarchies at the same time, the filters are applied in the order that the user added them, using subselects, which ensures an intuitive filter experience where filtering is always based on the totals currently displayed in the PivotTable.
The reason why subselects are only used with Analysis Services 2005 SP2 or newer versions is that Analysis Services 2005 introduced a provider property in SP2 so that client applications can determine whether the provider supports subselects. The provider property is MDPROP_MDX_SUBQUERIES.
By reading this provider property to determine whether subselects are supported, Excel exposes the new filtering features with any OLAP provider that implements this property (and supports other fundamental OLAP provider capabilities needed, I included a link to more information on provider properties that Excel reads in the additional resources section below).
Now, let's discuss the specific features affected by using subselects for filtering. I'll start with filtering individual calculated members.
Filtering individual calculated members with Excel 2007 PivotTables connected to Analysis Services 2005 SP2+ cubes
Calculated members are not supported in subselects with Analysis Services 2005 so Excel 2007 does not offer filtering on individual calculated members for Analysis Services 2005 SP2+ servers.
However, you can choose to display all calculated members, or no calculated members at all, in the PivotTable Options dialog box using the "Show calculated members from OLAP server" option.
Note that this does not apply to calculated members in the Measures hierarchy (calculated measures); those are always displayed regardless of the option.
PivotTable Options dialog with the "Show calculated members from OLAP server" option
The screenshot below illustrates the filter drop down in a PivotTable for a hierarchy with calculated members ("Budget Variance" and "Budget Variance %").
Note that the checkboxes for the calculated members are disabled and therefore cannot be unselected.
Calculated members cannot be individually selected when subselects are used for filtering with Analysis Services 2005 SP2+
Non-visual totals with Excel 2007 PivotTables connected to Analysis Services 2005 SP2+ cubes
Another implicit behavior of subselects with Analysis Services 2005 is to always generate visual totals.
For this reason, PivotTables created using Excel 2007 do not allow the user to turn off visual totals with Analysis Services SP2+ cubes.
The first screenshot below illustrates a PivotTable with visual totals. The total for United States is the sum of the states currently in the filter (California, New York and Washington).
PivotTable displaying visual totals
The second screenshot illustrates a PivotTable with non-visual totals. The total for United States is not affected by the fact that some states are filtered out; it is still showing the total sales amount for all existing states.
PivotTable displaying non-visual totals
Workarounds
Individually filtering calculated members and generating non visual totals are important features for common scenarios. The Excel and Analysis Services teams are working together on a future solution for lifting these limitations and this section outlines current workarounds for enabling these features in Excel 2007 with Analysis Services 2005 SP2+.
The workaround for creating PivotTables that support both non visual totals and filtering individual calculated members with Analysis Services 2005 SP2+ cubes is to create PivotTables in Excel 2007 with a pre-2007 version.
PivotTable versioning was introduced in Excel 2000. PivotTables created with a certain version ensures that the PivotTable is compatible with the corresponding version of Excel in that it is generally created with the same default settings as in that version of Excel and it exhibits the same behaviors. This is also true when using the Excel PivotTable object model through code. A benefit from this is that users can expect macros created in previous versions of Excel to still work exactly the same way in newer versions of Excel.
The table below outlines the different PivotTable versions supported in Excel as well as which version is the default created in different versions of Excel.
Version of Excel
Version number
Default PivotTable version created
Excel 2000
9
PivotTable.Version = 0 (xlPivotTableVersion2000)
Excel 2002
10
PivotTable.Version = 1 (xlPivotTableVersion10)
Excel 2003
11
Excel 2007
12
PivotTable.Version = 3 (xlPivotTableVersion12)
There is an additional PivotTable version supported in Excel 2007, namely version 2 (xlPivotTableVersion11). However, there is no functional difference between version 1 and version 2 PivotTables. Since no version of Excel creates version 2 PivotTables by default, it isn't included in the table above. Version 2 was added in Excel 2007 for completeness although Excel 2003 creates version 1 PivotTables.
For PivotTables with a version number less than 3, Excel will generate Excel 2003 style MDX queries (no use of subselects) and will support filtering calculated members individually and toggling visual totals.
As indicated above, the drawback of working with old version PivotTables is that the new filtering features are not available.
There are two ways in Excel 2007 to create PivotTables with a specific version:
When Excel 2007 is in Compatibility Mode, version 1 PivotTables are created
The VBA code below creates a version 1 (PivotTable.Version = xlPivotTableVersion10) PivotTable, turns on the new Excel 2007 default layout and turns off visual totals. It is using the sample Adventure Works cube that comes with Analysis Services 2005. You'll need to change the OLAPServerName to your actual OLAP server name and make sure there is a worksheet named Sheet1 which is empty in the area where the PivotTable is placed to try out this code.
Sub CreateV1PivotTable()
With ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, Version:=xlPivotTableVersion10)
.Connection = Array("OLEDB;Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=Adventure Works DW;Data Source=OLAPServerName;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error").CommandType = xlCmdCube.CommandText = Array("Adventure Works").MaintainConnection = True.CreatePivotTable TableDestination:="Sheet1!R1C1", TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
End With
ActiveSheet.PivotTables("PivotTable1").RowAxisLayout xlCompactRowActiveSheet.PivotTables("PivotTable1").InGridDropZones = FalseActiveSheet.PivotTables("PivotTable1").TableStyle2 = "PivotStyleLight16"ActiveSheet.PivotTables("PivotTable1").VisualTotals = False
End Sub
The screenshot below shows the PivotTable Options dialog box for a version 1 (xlPivotTableVersion10) PivotTable in Excel 2007 with the option to toggle visual totals using the "Include filtered items in totals" checkbox. Non-visual totals are displayed when the checkbox is selected.
OLAP PivotTables with a version less than 3 in Excel 2007 allow users to turn off visual totals in OLAP PivotTables using the PivotTable Options dialog box ("Include filtered items in totals")
Note that if you save to an Excel 2007 file format while Excel is in compatibility mode, all PivotTables with a version number less than 3 will be marked for upgrade to version 3 (xlPivotTableVersion12) and the next refresh you perform on each PivotTable will do the actual upgrade. Once a PivotTable is upgraded to version 3, you'll lose the ability to filter on calculated members individually and toggling visual totals.
If you want to avoid the automatic upgrade, before refreshing the PivotTables, go to each one and set PivotTable.PivotCache.UpgradeOnRefresh to False using the object model. For example, in the immediate window (press ALT+F11 and then CTRL+G to display the immediate window) type and run Activecell.PivotTable.PivotCache.UpgradeOnRefresh = False with the active cell inside the PivotTable.
Turning off PivotTable version upgrade for the selected PivotTable in the Immediate window
Additional resources
Excel 2007 and SQL Server Analysis Services 2005 Service Pack 2
http://blogs.msdn.com/excel/archive/2007/05/06/excel-2007-and-sql-server-analysis-services-2005-service-pack-2.aspx
Excel 2007 Document: Designing SQL Server 2005 Analysis Services Cubes for Excel 2007 PivotTables
http://www.microsoft.com/downloads/details.aspx?FamilyId=2D779CD5-EEB2-43E9-BDFA-641ED89EDB6C&displaylang=en
OLE DB for OLAP Properties Used by Excel 2007
http://msdn2.microsoft.com/en-us/library/bb407625.aspx
Creating calculated members/measures and sets in Excel 2007 OLAP PivotTables
Excel doesn't offer a user interface for creating calculated members/measures and sets in PivotTables connected to OLAP cubes. However, in the object model there is support for creating personal calculations and sets in PivotTables with OLAP data sources.
The CalculatedMembers collection holds calculations and sets private to a PivotTable and it has an Add method for creating new calculations and sets.
Below are examples of creating a calculated measure, a calculated member and a named set using the CalculatedMembers collection of the PivotTable object. All the examples are using the sample Adventure Works database that comes with Analysis Services 2005.
Example of adding a calculated measure in an Excel PivotTable connected to an OLAP data source:
Sub AddCalculatedMeasure()
Dim pvt As PivotTableDim strName As StringDim strFormula As String Set pvt = Sheet1.PivotTables("PivotTable1")strName = "[Measures].[Internet Sales Amount 25 %]"strFormula = "[Measures].[Internet Sales Amount]*1.25"pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedMember
Dim pvt As PivotTableDim strName As StringDim strFormula As String
Set pvt = Sheet1.PivotTables("PivotTable1")strName = "[Measures].[Internet Sales Amount 25 %]"strFormula = "[Measures].[Internet Sales Amount]*1.25"pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedMember
Calculated measure "Internet Sales Amount 25%" added to an OLAP PivotTable using the CalculatedMembers collection in the object model
Example of adding a calculated member to the Adventure Works Product level of the Product Categories hierarchy in an Excel PivotTable connected to an OLAP data source:
Sub AddCalculatedMember()
Dim pvt As PivotTableDim strName As StringDim strFormula As String Set pvt = Sheet1.PivotTables("PivotTable1")strName = "[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38 25 %]"strFormula = "[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38]*1.25"pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedMemberpvt.ViewCalculatedMembers = True
Set pvt = Sheet1.PivotTables("PivotTable1")strName = "[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38 25 %]"strFormula = "[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38]*1.25"pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedMemberpvt.ViewCalculatedMembers = True
The screenshot below shows the PivotTable with the calculated member ("Mountain-100 Silver, 38 25%") added to the Product level of the Product Categories hierarchy.
Calculated member "Mountain-100 Silver, 38 25%" added to an OLAP PivotTable using the CalculatedMembers collection in the object model
Example of adding a named set in an Excel PivotTable connected to an OLAP data source:
Sub AddNamedSet()
Dim pvt As PivotTableDim strName As StringDim strFormula As StringDim cbf As CubeField Set pvt = Sheet1.PivotTables("PivotTable1")strName = "[My Mountain Bikes]"strFormula = "[Product].[Product Categories].[Bikes].[Mountain Bikes].children"pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedSetSet cbf = pvt.CubeFields.AddSet(Name:="[My Mountain Bikes]", Caption:="Mountain Bikes")
Dim pvt As PivotTableDim strName As StringDim strFormula As StringDim cbf As CubeField
Set pvt = Sheet1.PivotTables("PivotTable1")strName = "[My Mountain Bikes]"strFormula = "[Product].[Product Categories].[Bikes].[Mountain Bikes].children"pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedSetSet cbf = pvt.CubeFields.AddSet(Name:="[My Mountain Bikes]", Caption:="Mountain Bikes")
The screenshot below shows the PivotTable with the named set ("Mountain Bikes") added.
Named set "Mountain Bikes" added to an OLAP PivotTable using the CalculatedMembers collection in the object model
Note that Excel 2007 only support named sets consisting of members from a single hierarchy.
Also note that even though Excel Services 2007 doesn't support Excel workbooks with macros/code, you can still use code as illustrated here to create calculated members/measures and named sets, remove the code after creating these and then publish the workbook to Excel Services. This way the calculations created in Excel can be exposed through Excel Services.
Comments: (9) Collapse
One year ago I opened an incident to fix the AS2005 SP2 issues with filtering calculated members. After a few months, the answer was that it was a "by design" behavior and no fix would be created. One year after, I see that this is still an issue affecting more and more people and I still think MS had not handled this issue in a good way, limiting the adoption of Excel 2007 and sometimes of SSAS 2005.
The fact that there is not a real fix for a breaking change introduced by a Service Pack one year ago is really unbelieavable. Workaround like that of using an older version of the pivot table cannot be considered a workaround at all!
Marco
Hi There
I've tried to get help on this elsewhere with no joy. I have a pivot table based on a SQL Server 2005 cube. At the moment the database behind the cube has dates until the end of this year in descending order. When the data is loaded into a pivottable and the dates are selected as a report filter, they are not in descending order. I would also like a way to stop the dates in the future from being displayed in the report filter.
1. Timothy Zapawa’s book “Excel 2007 Advanced Report Development” pp276 said I could drag that field into the row labels or column labels area, sort it there, then drag it back to the report filter. This hasn’t worked.
2. Another option was to apply filters by manually adding the cube field to the pivottable (see msdn2.microsoft.com.en-us/.../bb256319.aspx and ssas-info.com/RamunasBalukonisBlog)
First of all, I’ve needed to get a list of all of the programmatic field names for the pivottable. This didn’t work because the cube based fields aren’t referred to as PivotFields …(Application Error 1004)
Sub List_PvtFields()
Dim pvtTable As PivotTable
Dim pvtField As PivotField
Dim objNewSheet As Object
Dim intRow As Integer
Set objNewSheet = Worksheets.Add
objNewSheet.Activate
intRow = 1
Set pvtTable = ActiveSheet.PivotTables(1)
For Each pvtField In pvtTable.PivotFields
objNewSheet.Cells(intRow, 1).Value = pvtField.Name
intRow = intRow + 1
Next pvtField
The following did work…
Sub list_cube_fields()
Dim objCubeFld As Object
For Each objCubeFld In Worksheets("DailyGraph").PivotTables(1).CubeFields
objNewSheet.Cells(intRow, 1).Value = objCubeFld.Name
Next objCubeFld
Next I followed (see msdn2.microsoft.com.en-us/.../bb256319.aspx) and I think that the following line worked….
ActiveSheet.PivotTables _("ptDailyGraph").CubeFields("[Date].[Year]").CreatePivotFields
So this should have added this cube field as a pivottable field. But this next line doen’t work…(I get “RunTime Error 438 – Object does not support this property or method”)
ActiveSheet.PivotTables("ptDailyGraph").PivotField("[Date].[Year]").VisibleItemsList = Array("[Date].[Year].&[2006]", "[Date].[Year].&[2007]")
I’ve also tried this line…and got the same error message…
ActiveSheet.PivotTables("ptDailyGraph").PivotField("[Date].[Year]").AutoSort
xlDescending
Any ideas?
--
Thanks a lot.
I'm trying this out with Excel 2003 and an offline OLAP cube (.cub file) generated via Microsoft Query's Offline Cube Wizard, and, unfortunately, it isn't working out so well.
For your code that shows:
Set pvt = Sheet1.PivotTables("PivotTable1")
strName = "[Measures].[Internet Sales Amount 25 %]"
strFormula = "[Measures].[Internet Sales Amount]*1.25"
pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedMember
I can only get a constant integer measure to be added successfully. That is, if I set strFormula = 1, or strFormula = "2", then it works. If I try something as simple as strFormula = "1+1", or strFormula = "[Measures].[Internet Sales Amount]", or strFormula = 2.52 though, it fails.
Does anyone know if this is a limitation of Excel 2003, the Offline Cube Wizard, or both?
I'm searching for a way to get average and standard deviation calculations in the cube using these technologies.
I got a chance to experiment a little more.
Even Using OLAP 8.0 or 9.0 in Excel 2007 (or 2003), with or without "Show calculated members from OLAP server" checked, I can't get this to work with my offline cube.
If I look at the DLL source of the error for the pvt.CalculatedMembers.Add line, it tells me "syntax error in axis definition" (if I try strFormula = "[Measures].[Internet Sales Amount]") or "syntax error, did not expect end of statement but found extra text near "+1" " (for example, if I tried strFormula = "1+1".
So unless it's some OLAP driver setting issue somewhere, I'm guessing this is a limitation of offline cubes? (at least those created with the Office Offline Cube Wizard)
Eric, creating session members/calculations are supported in Analysis Services local cubes as long as all the entities referenced by the expressions for these members/calculations are included in the local cube definition.
I just created a local cube from within Excel 2007 based on the Adventure Works cube and then I used the Excel object model code that you tried and I was able to create the calculations just fine.
If you can provide some more details on the specific steps you take when creating the local cube etc. I will do my best to try to help out.
skyMike001, for OLAP PivotTables in Excel, members are listed in the order specified on the OLAP server by default (Data source order).
For a time dimension, if you make sure to sort the attribute members by key (OrderBy=Key) on the OLAP server, and the Key is a DateTime type attribute, then Excel will list the members in chronological order.
If you use the sorting options in Excel OLAP PivotTables however, member captions are retrieved as strings (even when they really are dates) and therefore sorting hierarchies with dates will typically not give you what you want but instead do a string based sort.
So to control sort order for dates in Excel OLAP PivotTables, you typically need to rely on the sorting capabilities of the OLAP server.
In non-OLAP PivotTables you can specify any sort order for items of fields by moving them around manually and that order will be used in the report filter field drop down as well as on rows and columns. Also, in non-OLAP PivotTables, date values are treated as dates (not strings) so sorting in the PivotTable will sort chronologically (ascending or descending depending on what you choose).
You can also manually specify the sort order for members of an OLAP hierarchy on rows and columns in the PivotTable but when the hierarchy is moved to the report filter area, this order is not used since the filter drop down is populated by a query to the OLAP server when it is opened. Therefore members are always listed in the order specified on the OLAP server in the filter drop downs.
As you discovered, in the object model for OLAP PivotTables, CubeFields represent hierarchies and PivotFields represent levels within hierarchies. Excel does not keep track of all levels of all hierarchies at all times so for hierarchies not added to the PivotTable yet, you need to use the CreatePivotFields method to create PivotFields representing levels of those hierarchies if you want to work with them.
Here is an object model example of sorting and filtering a hierarchy before adding it to the PivotTable (and then adding it to rows at the end):
Sub SortAndFilter()
Dim myPT As PivotTable
Set myPT = ActiveSheet.PivotTables("PivotTable1")
With myPT
.CubeFields("[Customer].[Customer Geography]").CreatePivotFields
.PivotFields("[Customer].[Customer Geography].[Country]").AutoSort xlDescending, "[Customer].[Customer Geography].[Country]"
.PivotFields("[Customer].[Customer Geography].[Country]").VisibleItemsList = Array("[Customer].[Customer Geography].[Country].&[United States]", "[Customer].[Customer Geography].[Country].&[Germany]", "[Customer].[Customer Geography].[Country].&[Australia]")
.PivotFields("[Customer].[Customer Geography].[State-Province]").VisibleItemsList = Array("")
.PivotFields("[Customer].[Customer Geography].[City]").VisibleItemsList = Array("")
.PivotFields("[Customer].[Customer Geography].[Postal Code]").VisibleItemsList = Array("")
.PivotFields("[Customer].[Customer Geography].[Customer]").VisibleItemsList = Array("")
.CubeFields("[Customer].[Customer Geography]").Orientation = xlRowField
Hi Allan,
I have a question regarding PivotTable security.
We want to publish PivotTable reports with external connections to our AS2005 cubes to a document library on MOSS. We want to security trim external data based on users' permissions on the AS DB when they open the workbook either in browser or in Excel.
I was able to make it to work in browser using refreshing on open Excel connection property and MOSS view items only permission based on recommendation in a January blog entry blogs.msdn.com/.../personalized-data-in-excel-services.aspx. But then users would not be able to open the workbook in Excel any more, since if i give them the permissions then when refreshing on open failed, users still can see data originally published by the workbook authors. The behavior is same whether in browser or in Excel.
It seems to me Excel refresh on open is not designed as a security mechanism, but rather as an convenience to synchronize data. But i notice there is another check box called remove data from external data range before saving the workbook. That appears exactly what we are looking for. But unfornately it is disabled for AS2005 data source (i checked it works with SQL data source)
The bottom line is why it is disabled for olap data source and how can we accomplish our security requirements?
thanks
Hank
Hello,
I have a question about Pivot tables. I want to change several "sum of ...." to "average ..." with one move. How can I do this? When I select multiples and format to change to average it just changes one. Can anyone help me?
I have a question about OLAP HTTP Datasource and it's related security. My Datasource is running on IIS6 under IUSR account.
One of my users is exporting the "Export to Excel" from a OWC11 cube on the web and along with that comes the datasource. The user then sends the spreadsheet to some other user and that user has access to the cube as well. How do I secure it such that the first user is still able to download the Excel (with or without the connection string) such that the cube's data is not available to the 2nd user?
Can you guys help?
Thanks
AM
Comments: (loading) Collapse