将Excel PowerPivot记录集导出为脱机多维数据集

时间:2019-04-30 15:04:50

标签: vba ssas mdx powerpivot powerquery

我有一个以Power Query为源的PowerPivot模型。可以从中创建一个离线多维数据集吗?

我尝试从PP中创建数据透视表,然后使用ivotttable.createcubefile方法,但出现错误:

A cube file cannot be created from another cube file. The source "$Embedded$" is a cube file.

我还尝试了ADODB和ADOMD连接。

对于ADODB,此处介绍的方法可用于编写CSV:https://www.kasperonbi.com/export-a-table-or-dax-query-from-power-pivot-to-csv-using-vba/

但是我无法运行

之类的MDX查询
CREATE GLOBAL CUBE 

对于ADOMD,我从这里https://www.engram9.info/excel-2007-vba-2/creating-an-offline-cube-using-ado-md-and-vba.html尝试了一种方法

但是代码无法为ADOMD.Catalog对象设置ActiveConnection属性。我使用

ThisWorkbook.Model.DataModelConnection.ModelConnection.ADOConnection

设置ActiveConnection属性时。

我使用atm的完整代码

Option Explicit

Public Sub Create_Local_Cube()
    Dim ObjCatalog As New ADOMD.Catalog
    Dim ObjCellset As New ADOMD.Cellset
    Dim StrConnection As String
    Dim strmdx As String

    ThisWorkbook.Model.Initialize

'Create connection string
    'StrConnection = StrConnection & "Provider=MSOLAP;Data Source=D4SBY981;"
    'StrConnection = StrConnection & "Initial Catalog=AdventureWorks;"
    StrConnection = "Provider=MSOLAP.5;Persist Security Info=True;Initial Catalog=Microsoft_SQLServer_AnalysisServices;Data Source=$Embedded$;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Subqueries=0;Optimize Response=7;Update Isolation Level=2"

'Create the MDX Query

    strmdx = strmdx & "CREATE GLOBAL CUBE [MyCustomCube]"
    strmdx = strmdx & "STORAGE 'C:\MyCustomCube.cub' "
    strmdx = strmdx & "FROM [mergeMarinDs] "
    'StrMDX = StrMDX & "("
    'StrMDX = StrMDX & "MEASURE [Analysis Services Tutorial].[Internet Sales-Sales Amount], "
    'StrMDX = StrMDX & "DIMENSION [Analysis Services Tutorial].[Customer], "
    'StrMDX = StrMDX & "DIMENSION [Analysis Services Tutorial].[Product]"
    'StrMDX = StrMDX & ")"

    strmdx = "EVALUATE mergeMarinDs"

'Feed the cellset object your MDX Query
    ObjCellset.source = strmdx

'Point catalog and cellset objects to the data source using your connection string
    ObjCatalog.ActiveConnection = ThisWorkbook.Model.DataModelConnection.ModelConnection.ADOConnection
    ObjCellset.ActiveConnection = ThisWorkbook.Model.DataModelConnection.ModelConnection.ADOConnection

'Open Cellset and fill the local cube
    ObjCellset.Open

'Clean up

    Set ObjCatalog = Nothing
    Set ObjCellset = Nothing

End Sub

我也尝试过从一个压缩的工作簿中提取item.data文件,但是我不知道如何在转换为.abf格式时恢复此文件,如本演示文稿的幻灯片13中所述https://slideplayer.com/slide/8455428/ < / p>

关于是否可以将PP模型导出为脱机多维数据集的任何建议?

0 个答案:

没有答案