简体   繁体   English

从 PowerPivot 导出数据

[英]Exporting data from PowerPivot

I have an enormous PowerPivot table (839,726 rows), and it is simply too big to copy-paste into a regular spread sheet.我有一个巨大的 PowerPivot 表(839,726 行),它太大了,无法复制粘贴到常规电子表格中。 I have tried copying it and then reading it directly into R using the line data = read.table("clipboard", header = T) , but neither of these approaches work.我尝试复制它,然后使用行data = read.table("clipboard", header = T)将其直接读入 R,但这些方法都不起作用。 I am wondering if there is some add-on or method I can use to export my PowerPivot table as a CSV or .xlsx?我想知道是否有一些插件或方法可以用来将我的 PowerPivot 表导出为 CSV 或 .xlsx? Thanks very much非常感谢

  • Select all the PowerPivot table选择所有 PowerPivot 表
  • Copy the data复制数据
  • Past the data in a text file (for example PPtoR.txt)将数据粘贴到文本文件中(例如 PPtoR.txt)
  • Read the text file in R using tab delimiter: read.table("PPtoR.txt", sep="\\t"...)使用制表符分隔符读取 R 中的文本文件: read.table("PPtoR.txt", sep="\\t"...)

To get a PowerPivot table into Excel:要将 PowerPivot 表导入 Excel:

  1. Create a pivot table based on your PowerPivot data.根据您的 PowerPivot 数据创建数据透视表。
  2. Make sure that the pivot table you created has something in values area, but nothing in filters-, columns- or rows areas.确保您创建的数据透视表在值区域中有内容,但在过滤器、列或行区域中没有内容。
  3. Go to Data > Connections.转至数据 > 连接。
  4. Select your Data model and click Properties.选择您的数据模型并单击属性。
  5. In Usage tab, OLAP Drill Through set the Maximum number of records to retrieve as high as you need (maximum is 9999999 records).在“使用”选项卡中,“OLAP 钻取”将“最大记录数”设置为您需要的尽可能高的检索数(最大为 9999999 条记录)。
  6. Double-click the measures area in pivot table to drill-through.双击数据透视表中的度量区域以进行钻取。

another solution is另一个解决方案是

  • import the Powerpivot model to PowerBi desktop将 Powerpivot 模型导入 PowerBi 桌面
  • export the results from PowerBI desktop using a Powershell script使用 Powershell 脚本从 PowerBI 桌面导出结果

here is an example这是一个例子

https://github.com/djouallah/PowerBI_Desktop_Export_CSV https://github.com/djouallah/PowerBI_Desktop_Export_CSV

A pure Excel / VBA solution is below.下面是一个纯 Excel/VBA 解决方案。 This is adapted from the code here to use FileSystemObject and write 1k rows at a time to the file.这改编自此处的代码以使用 FileSystemObject 并一次向文件写入 1k 行。 You'll need to add Microsoft ActiveX Data Objects Library and Microsoft Scripting Runtime as references.您需要添加 Microsoft ActiveX Data Objects Library 和 Microsoft Scripting Runtime 作为参考。

Option Explicit

Public FSO As New FileSystemObject

Public Sub ExportToCsv()

    Dim wbTarget As Workbook
    Dim ws As Worksheet
    Dim rs As Object
    Dim sQuery As String

    'Suppress alerts and screen updates
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With

    'Bind to active workbook
    Set wbTarget = ActiveWorkbook

    Err.Clear

    On Error GoTo ErrHandler

    'Make sure the model is loaded
    wbTarget.Model.Initialize

    'Send query to the model
    sQuery = "EVALUATE <Query>"
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open sQuery, wbTarget.Model.DataModelConnection.ModelConnection.ADOConnection
    Dim CSVData As String
    Call WriteRecordsetToCSV(rs, "<ExportPath>", True)

    rs.Close
    Set rs = Nothing

ExitPoint:
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    Set rs = Nothing
    Exit Sub

ErrHandler:
    MsgBox "An error occured - " & Err.Description, vbOKOnly
    Resume ExitPoint
End Sub



Public Sub WriteRecordsetToCSV(rsData As ADODB.Recordset, _
        FileName As String, _
        Optional ShowColumnNames As Boolean = True, _
        Optional NULLStr As String = "")
    'Function returns a string to be saved as .CSV file
    'Option: save column titles

    Dim TxtStr As TextStream
    Dim K As Long, CSVData As String

    'Open file
    Set TxtStr = FSO.CreateTextFile(FileName, True, True)

    If ShowColumnNames Then
        For K = 0 To rsData.Fields.Count - 1
            CSVData = CSVData & ",""" & rsData.Fields(K).Name & """"
        Next K

        CSVData = Mid(CSVData, 2) & vbNewLine
        TxtStr.Write CSVData
    End If

    Do While rsData.EOF = False
        CSVData = """" & rsData.GetString(adClipString, 1000, """,""", """" & vbNewLine & """", NULLStr)
        CSVData = Left(CSVData, Len(CSVData) - Iif(rsData.EOF, 3, 2))
        TxtStr.Write CSVData
    Loop

    TxtStr.Close

End Sub

Here is a lovely low-tech way: https://www.sqlbi.com/articles/linkback-tables-in-powerpivot-for-excel-2013/这是一个可爱的低技术方式: https : //www.sqlbi.com/articles/linkback-tables-in-powerpivot-for-excel-2013/

I think the process is a little different in Excel 2016. If you have Excel 2016, you just go to the data tab, go to Get External Data, and then Existing Connections (and look under Tables).我认为 Excel 2016 中的过程略有不同。如果您有 Excel 2016,您只需转到数据选项卡,转到获取外部数据,然后转到现有连接(并在表下查看)。

The other important thing is to click on Unlink (under Table Tools - Design - External Table Data).另一件重要的事情是单击取消链接(在表工具 - 设计 - 外部表数据下)。 This unlinks it from the source data, so it really is just an export.这会将其与源数据断开链接,因此它实际上只是一个导出。

You can copy that data into another workbook should you wish to.您可以根据需要将该数据复制到另一个工作簿中。

Data in Power Pivot is modeled, using DAX Studio to export data to csv or SQL. Power Pivot 中的数据经过建模,使用 DAX Studio 将数据导出到 csv 或 SQL。 after finished, you will see that Each model corresponds to a CSV file or SQL table.完成后,您会看到每个模型对应一个 CSV 文件或 SQL 表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM