<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Analysis Services', 'PivotTable', and 'MDX'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Analysis+Services,PivotTable,MDX&amp;orTags=0</link><description>Search results matching tags 'Analysis Services', 'PivotTable', and 'MDX'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Display the MDX query of an Excel 2007 PivotTable</title><link>http://sqlblog.com/blogs/marco_russo/archive/2007/01/18/display-the-mdx-query-of-an-excel-2007-pivottable.aspx</link><pubDate>Thu, 18 Jan 2007 10:51:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:605</guid><dc:creator>sqlbi</dc:creator><description>&lt;P&gt;Often end users use Excel to navigate into the cube. Then they may ask you to produce a report using the same data. It would be useful to get the MDX query used by Excel. Moreover, Excel 2007 offers a good MDX quality of the produced query against Analysis Services 2005 (much better than Excel 2003).&lt;/P&gt;
&lt;P&gt;I don't know why Excel doesn't have such a function. I created a simple Excel macro that add an item to the PivotTable menu. A code that add a button in the Ribbon would be very welcome!&lt;/P&gt;
&lt;P&gt;If you want to add these macro for all Excel sheets, you have to modify the PERSONAL.XLS file contained into "Documents and Settings\[Username]\Application Data\Microsoft\Excel\XLSTART".&lt;/P&gt;
&lt;P&gt;This is the macro Workbook_Open that is executed when you open a workbook.&lt;/P&gt;
&lt;P style="BACKGROUND:#ffff99;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Lucida Console';mso-bidi-font-family:Arial;"&gt;Private Sub Workbook_Open()&lt;BR&gt;&amp;nbsp;&amp;nbsp; Dim ptcon As CommandBar&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; 'See the following for list of menus in excel&lt;BR&gt;&amp;nbsp;&amp;nbsp; 'http://support.microsoft.com/support/kb/articles/Q213/5/52.ASP&lt;BR&gt;&amp;nbsp;&amp;nbsp; 'Title: XL2000: List of ID Numbers for Built-In CommandBar Controls&lt;BR&gt;&amp;nbsp;&amp;nbsp; Set ptcon = Application.CommandBars("PivotTable context menu")&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Lucida Console';mso-bidi-font-family:Arial;"&gt;insertDisplayMDX:&lt;BR&gt;&amp;nbsp;&amp;nbsp; Dim cmdMdx As CommandBarControl&lt;BR&gt;&amp;nbsp;&amp;nbsp; For Each btn In ptcon.Controls&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If btn.Caption = "MDX Query" Then GoTo doneDisplayMDX&lt;BR&gt;&amp;nbsp;&amp;nbsp; Next btn&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ' Add an item to the PivotTable context menu.&lt;BR&gt;&amp;nbsp;&amp;nbsp; Set cmdMdx = ptcon.Controls.Add(Type:=msoControlButton, temporary:=True)&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp; ' Set the properties of the menu item.&lt;BR&gt;&amp;nbsp;&amp;nbsp; cmdMdx.Caption = "MDX Query"&lt;BR&gt;&amp;nbsp;&amp;nbsp; cmdMdx.OnAction = "DisplayMDX"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;doneDisplayMDX:&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Lucida Console';mso-bidi-font-family:Arial;"&gt;End Sub&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Lucida Console';mso-bidi-font-family:Arial;"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;And this is the DisplayMDX subroutine, that you can insert in a separate module.&lt;/P&gt;
&lt;P style="BACKGROUND:#ffff99;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Lucida Console';mso-bidi-font-family:Arial;"&gt;Sub DisplayMDX()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim mdxQuery As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pvt As PivotTable&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim ws As Worksheet&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pvt = ActiveCell.PivotTable&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mdxQuery = pvt.MDX&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Add a new worksheet.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set ws = Worksheets.Add&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ws.Range("A1") = mdxQuery&lt;BR&gt;End Sub&lt;BR&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;When you right-click the PivotTable, the last item of the menu will be "MDX Query". If you click it, a new worksheet is created with the query in A1 cell. This is the fastest way to copy and paste it into other programs. I would like to be able copying directly into clipboard, but I still haven't found a reliable way to do it. If someone has some good idea, please contact me or comment to this post.&lt;/P&gt;
&lt;P&gt;I attached a copy of a PERSONAL.XLS for the lazy of you!&lt;/P&gt;</description></item></channel></rss>