在 Power BI Desktop 中合併二進位檔案Combine binaries in Power BI Desktop

將多個具有相同結構描述的檔案合併成單一邏輯資料表,是一種將資料匯入 Power BI Desktop 中的強大方法。One powerful approach to importing data into Power BI Desktop is to combine multiple files, which have the same schema, into a single logical table. 這個便利又熱門的方法在 Power BI Desktop 的 2016 年 11 月版本 (及後續版本) 中獲得了便利性及擴充能力的提升,如本文所述。With the November 2016 release of Power BI Desktop (and subsequent releases), this convenient and popular approach has been made more convenient and more expansive, as described in this article.

若要啟動合併同一個資料夾中二進位檔的處理序,請選取 [取得資料] > [檔案] > [資料夾]。To start the process of combining binaries from the same folder, select Get Data > File > Folder.

先前的合併二進位檔案行為Previous combine binaries behavior

Power BI Desktop 的 2016 年 11 月版本之前,您可以用 [合併二進位檔案] 轉換來合併特定檔案類型,但有幾項限制:Prior to the November 2016 release of Power BI Desktop, you could combine certain file types with the combine binaries transform, but there were limitations:

  • 在檔案合併成單一資料表之前,並不是每一個個別檔案都會轉換。Transformations were not considered for each individual file before the files were combined into a single table. 因此,您通常需要合併檔案,然後在編輯程序中篩選資料列,以篩選出「標頭值」。As such, you often had to combine files, then filter out header values by filtering rows as part of the edit process.
  • [合併二進位檔案] 轉換僅適用於「文字」或 CSV 檔案,而不適用於其他支援的檔案格式,例如 Excel 活頁簿、JSON 檔案等。The Combine binaries transform only worked for text or CSV files, and didn't work on other supported file formats such as Excel workbooks, JSON files, and others.

客戶要求更直覺式的 [合併二進位檔案] 作業,因此我們加強了轉換功能。Customers asked for more intuitive operation of the combine binaries operation, so the transform was enhanced.

目前的合併二進位檔案行為Current combine binaries behavior

Power BI Desktop 現在能夠更有效率地處理 [合併二進位檔案]。Power BI Desktop now handles the combine binaries more effectively. 您可以從 [查詢編輯器] 中的 [首頁] 功能區索引標籤或資料行本身選取 [合併二進位檔案]。You start by selecting combine binaries, either from the Home ribbon tab in Query Editor, or from the column itself.

[合併二進位檔案] 轉換現在的行為如下:The combine binaries transform now behaves as follows:

  • [合併二進位檔案] 轉換會分析每個輸入檔案,並判斷要使用的正確檔案格式,例如「文字」或「Excel 活頁簿」或 JSON 檔案。The combine binaries transform analyzes each input file, and determines the correct file format to use, such as text or Excel workbook or JSON file.
  • 轉換可讓您從第一個檔案 (例如「Excel 活頁簿」) 選取要擷取的特定物件。The transform allows you to select a specific object from the first file, for example, an Excel workbook, to extract.

  • [合併二進位檔案] 接著會自動執行下列動作:The combine binaries then automatically does the following:

    • 建立在單一檔案中執行所有必要擷取步驟的範例查詢。Creates an example query that performs all the required extraction steps in a single file.
    • 建立「函數查詢」,以將檔案/二進位檔案輸入參數化成「範例查詢」。Creates a function query that parameterizes the file/binary input to the exemplar query. 範例查詢和函數查詢會建立連結,因此範例查詢的變更會反映在函數查詢中。The exemplar query and the function query are linked, so that changes to the exemplar query are reflected in the function query.
    • 將「函數查詢」套用到具有輸入二進位檔案 (例如「資料夾」) 的原始查詢,使其在每個資料列上對二進位檔案輸入套用函數查詢,然後將產出的資料擷取展開為頂層資料行。Applies the function query to the original query with input binaries (for example, the Folder query) so it applies the function query for binary inputs on each row, then expands the resulting data extraction as top-level columns.

透過 [合併二進位檔案] 的新行為,只要二進位檔案的檔案類型和結構相同 (例如相同的資料行),您就可以輕鬆將其全部合併到指定的資料夾中。With the new behavior of combine binaries, you can easily combine all binaries within a given folder as long as they have the same file type and structure (as in, the same columns).

此外,您可以藉由修改自動建立的「範例查詢」輕鬆套用額外轉換或擷取步驟,而不需要花費心力修改或建立額外「函數查詢」步驟;對「範例查詢」進行的任何變更都會在已連結的「函數查詢」中自動產生。In addition, you can easily apply additional transformation or extraction steps by modifying the automatically created exemplar query, without having to worry about modifying or creating additional function query steps; any changes to the exemplar query are automatically generated in the linked function query.

後續步驟Next steps

您可以使用 Power BI Desktop 連接至各式各樣的資料。There are all sorts of data you can connect to using Power BI Desktop. 如需有關資料來源的詳細資訊,請參閱下列資源︰For more information on data sources, check out the following resources: