教學課程:Power BI 使用者的網狀架構

在本教學課程中,您將瞭解如何使用數據流 Gen2 和 Pipelines 將數據內嵌至 Lakehouse 並建立維度模型。 您也會瞭解如何在短短 45 分鐘內自動產生美觀的報表,以顯示從頭到尾的最新銷售數據。

讓我們開始吧!

  • 準備數據並將其載入 Lakehouse
  • 在 Lakehouse 中建置維度模型
  • 使用快速建立自動建立報表

必要條件

建立 Lakehouse 來儲存數據

首先,我們會建立 lakehouse 來儲存我們的數據、數據流 Gen2 來準備和轉換數據行,以及處理排程重新整理和電子郵件活動的協調流程的管線。


  1. 流覽至您的工作區,然後選取 [ 新增]。 然後選取 [ 全部顯示]。

    Screenshot of the Show all option in the new item menu.

  2. 在 [ 新增 專案建立] 畫面中,選取 [數據工程] 類別下的 [Lakehouse ]。

    Screenshot of Data engineering items.

  3. 將 Lakehouse 名稱設定為 SalesLakehouse。 然後選取建立

    Screenshot of naming a name Lakehouse.

  4. 進入 Lakehouse 編輯器之後,請選取 [新增數據流 Gen2]。

    注意

    您也可以從功能區選取 [取得數據],然後選取 [新增數據流 Gen2]。

    Screenshot of Get data drop down in the Lakehouse editor.

準備數據並將其載入您的 Lakehouse

採取下列步驟將數據載入 Lakehouse:

  1. 進入數據流 Gen2 的 Power Query Online 編輯器後,請從 Power Query 範本選取 [匯入],然後選擇從必要條件下載的範本檔案。

    Screenshot of watermarks in the Dataflows Gen2 editor.

  2. 選取 [數據載入查詢] 群組底下的 [DimDate] 查詢,然後選取 [設定連線]。 如有必要,請先將驗證類型設定為 [匿名],再選取 [連線]。

    Screenshot of the configure connection menu.

  3. 選取 DimDate 查詢之後,在資料預覽視窗中,選取左上方的圖示,將 DateKey 資料行的資料類型變更為 [日期/時間]。

    Screenshot of changing data types within the Power Query editor.

  4. 選取 [變更資料行類型] 視窗中的 [取代目前]。

    Screenshot of the change column type menu.

新增數據目的地

採取下列步驟來新增數據目的地:

  1. 選取 [DimDate] 數據表之後,從 [首頁] 索引標籤選取 [新增數據目的地],然後選取 [Lakehouse] 選項功能表項。

    Screenshot of the get data destination Lakehouse option.

  2. 如有必要,請將驗證設定為 [組織帳戶 ],然後選取 [ 下一步]。

    Screenshot of the Connect to data destination menu.

  3. 從導覽器中,選取本教學課程所使用的工作區,然後展開以檢視所有 Lakehouse 專案。 選取 [SalesLakehouse ],並確認已選取預設 的 [新增] 數據表 ,再選取 [ 下一步 ] 繼續。

    Screenshot of the destination target navigator item.

  4. Update 方法 設定為 [取代 ],然後選取 [ 儲存設定]。

    警告

    將 update 方法設定為 Replace 會刪除所有現有的數據,並將它取代為後續重新整理時的新數據。

    Screenshot of the destination settings menu option.

    注意

    在 Power Query Online 編輯器的右下角,您可以找到查詢的已設定資料目的地設定,您可以在其中進一步自定義或移除。

    Screenshot of the configured data destination.

  5. 在繼續進行本教學課程的下一節之前,請務必執行 與本節稍早相同的步驟 ,將 Lakehouse 設定為下列每個查詢的數據目的地。

    查詢
    DimCustomer
    DimEmployee
    DimProduct
    DimStore
  6. 選取 [數據轉換查詢] 群組底下的 FactOnlineSales 查詢,然後從 [首頁] 索引標籤選取 [新增數據目的地],然後選取 [Lakehouse] 選項。

    Screenshot of the Data destination Lakehouse target option.

  7. 如有必要,請將驗證設定為 [組織帳戶 ],然後選取 [ 下一步]。

    Screenshot of the Connect to data destination menu.

  8. 從導覽器中,選取本教學課程所使用的工作區,然後展開以檢視所有 Lakehouse 專案。 選取 [SalesLakehouse ],並確認已選取預設 的 [新增] 數據表 ,再選取 [ 下一步 ] 繼續。

    Screenshot of the destination target navigator window.

  9. Update 方法 設定為 [附加 ],然後選取 [ 儲存設定]。

    注意

    此程式會插入數據,並在每次後續重新整理時保留數據表中的現有數據列。

    Screenshot of the destination settings menu selection.

  10. 選取 [發佈 ] 以儲存數據流並結束 Power Query Online 編輯器。

    Screenshot of the publish button within Power Query Online.

  11. 將滑鼠停留在工作區中建立的數據流上方,選取省略號 (...) 和 [ 屬性] 選項。

    Screenshot of the dataflows properties in a workspace.

  12. 將數據流的名稱變更為 OnlineSalesDataflow ,然後選取 [ 儲存]。

    Screenshot of renaming a dataflow option.

協調數據管線

我們會使用管線,先協調數據流的重新整理。 如果發生錯誤,我們會傳送包含重要詳細數據的自定義 Outlook 電子郵件。

  1. 選取工作區中名為 SalesLakehouse 的 Lakehouse 專案。

    Screenshot of renaming an existing dataflow.

  2. 進入 Lakehouse 編輯器之後,請選取 [ 新增數據管線]。

    注意

    您也可以從功能區選取 [取得數據],然後選取 [新增數據管線]。

    Screenshot of watermarks in the Lakehouse editor.

  3. 將管線名稱設定為 SalesPipeline。 然後選取建立

    Screenshot of the pipeline name menu option.

  4. 選取 [取消],以關閉複製數據助理。 如果系統提示您確認結束複製資料視窗,請選取 [ 是,取消]。

    Screenshot of the copy data assistant menu.

  5. 進入管線編輯器之後,請選取 [新增管線活動],然後選取 [數據流]。

    注意

    您也可以從功能區選取 [數據流 ]。

    Screenshot of the pipeline watermark canvas and the add activity option.

  6. 選取管線編輯器內的數據流活動,並將其 [名稱] 值變更[一般] 區段中的 OnlineSalesActivity

    Screenshot of the dataflow name value.

  7. 在仍選取數據流活動之後,請選取 [設定],然後從 [數據流] 清單中選擇 [OnlineSalesDataflow]。 如果需要更新清單,請選取 [ 重新整理 ] 圖示。

    Screenshot of the dataflow selection setting.

  8. 選取 [活動] 索引標籤,然後選取 [Office365 Outlook] 活動。

    注意

    如果出現 [ 授與同意 ] 視窗,請選取 [ 確定],使用您的組織帳戶登入,然後選取 [ 允許存取]。

    Screenshot of the Office365 Outlook activity information.

  9. 管線編輯器中選取 Office365 Outlook 活動,並將其 [名稱] 值變更[一般] 區段中失敗的郵件。

    Screenshot of the Office365 Outlook activity name.

  10. 選取 [Office365 Outlook] 活動后,請選取 [設定]。 將 [ 件者] 字段更新至您的電子郵件位址,並將 [主旨管線] 失敗。 選取郵件本文的 [ Alt+Shift+D] 新增動態內容。

    注意

    您可以從 [進階] 屬性取得更多電子郵件設定選項,例如 [收件者]、[副本]、[副本]、[密件抄送]、[敏感度卷標]。

    Screenshot of the Office365 Outlook settings.

  11. [管線運算式產生器] 中,貼上下列表達式程式代碼區塊:

    @concat(
        'Pipeline: '
        , 
        , '<br>'
        , 'Workspace: '
        , 
        , '<br>'
        , 'Time: '
        , 
    )
    

    Screenshot of the Office365 Outlook activity with expression builder.

  12. 選取 [系統變數 ],然後選取下表中的對應名稱,以插入下列變數。

    值名稱 線條 系統變數
    管線: 3 管線標識碼
    工作區: 6 工作區識別碼

    Screenshot of the pipeline system variables.

  13. 選取 [函式 ],然後選取下表中的對應名稱,以插入下列函式。 完成後,請選取 [ 確定]。

    值名稱 線條 系統變數
    時間: 9 utcnow

    Screenshot of pipeline functions.

  14. 選取 [OnlineSalesActivity],然後從可用的路徑選項中,選取並保留 “X” (On fail) 以建立將在 [郵件失敗時] 上卸除的箭號。 如果 OnlineSalesActivity 失敗,現在將會叫用此活動。

    Screenshot of the on failure path.

  15. 從 [ 首頁] 索引標籤中,選取 [ 排程]。 更新下列組態之後,請選取 [ 套用 ] 以儲存變更。

    名稱
    排程執行 另一
    Repeat 每日
    Time 當時或之後

    Screenshot of on failure branch.

  16. 從 [ 首頁] 索引標籤中,選取 [ 執行]。 如果顯示對話框視窗,請選取 [ 儲存並執行 ] 選項以繼續。

    Screenshot of the run option from the home tab.

    若要監視管線的目前狀態,您可以檢視 [輸出 ] 數據表,其中顯示目前的活動進度。 數據表會定期自行重新整理,或者您可以手動選取重新整理圖示來更新它。

    Screenshot of the current pipeline activity progress.

  17. 當狀態傳回 成功時,您可以返回工作區,繼續進行本教學課程的下一節。

    Screenshot of the side rail with workspace selection.

在 Lakehouse 中建立語意模型

您載入的數據幾乎已準備好進行報告。 讓我們先使用 SQL 端點,在我們的 Lakehouse 中建立關聯性和 SQL 檢視。 這可讓我們輕鬆地存取語意模型中的數據,這是元數據模型,其中包含抽象化和修改為邏輯維度的實體資料庫物件。 其設計目的是根據業務結構呈現數據以供分析。

建立關聯

此模型是您可能會從數據倉儲中看到的星型架構:它類似於星形。 星號的中心是 Fact 數據表。 周圍數據表稱為維度數據表,其與 Fact 數據表有關聯性。


  1. 在工作區檢視中,選取名為 SalesLakehouseSQL 端點專案。

    Screenshot of the SQL endpoint item in a workspace.

  2. 在 [總管] 中,選取 畫面底部的 [模型 ] 檢視,以開始建立關聯性。

    Screenshot of the Model view selection.

  3. 將 CustomerKey 數據行FactOnlineSales 數據表拖放至 DimCustomer 數據表上的 CustomerKey,以建立關聯性。

  4. 在 [ 建立關聯性 ] 視窗中,確定您已選取正確的數據表、數據行和設定,如下表所示。 選取 [ 確認 ] 以繼續。

    設為使用中的關聯性 來源:表 1(欄) To: Table 2 (column) 基數 交叉篩選方向
    FactOnlineSales (CustomerKey) DimCustomer (CustomerKey) 多對一 (*:1) Single

    Screenshot of Relationship between the FactOnlineSales and DimCustomer table.

  5. 針對下表所列的每個其餘數據表和數據行執行這些相同的步驟,以建立關聯性。

    設為使用中的關聯性 來源:表 1(欄) To: Table 2 (column) 基數 交叉篩選方向
    FactOnlineSales (ProductKey) DimProduct (ProductKey) 多對一 (*:1) Single
    FactOnlineSales (StoreKey) DimStore (StoreKey) 多對一 (*:1) Single
    FactOnlineSales (DateKey) DimDate (DateKey) 多對一 (*:1) Single
    DimStore (StoreKey) DimEmployee (StoreKey) 多對一 (*:1) 兩者

    下圖顯示語意模型的已完成檢視,其中包含所有已建立的關聯性。

    Screenshot of table relationships in the model view pane.

在 DAX 撰寫量值

讓我們撰寫計算總銷售金額的基本量值。

  1. 選取 Tables 資料夾中的 FactOnlineSales 數據表。 在 [ 首頁] 索引標籤上,選取 [ 新增量值]。

    Screenshot of table relationships in the model view.

  2. 在公式編輯器中,複製並貼上或輸入下列量值來計算總銷售額。 選取要 認可的複選標記

    Total Sales Amount = SUM(FactOnlineSales[SalesAmount])
    

    Screenshot of Select the check mark to commit a DAX measure.

建立 SQL 檢視

讓我們撰寫一個 SQL 語句,以依月份計算總銷售額。 然後,我們會將此語句儲存為湖屋的檢視。 這可讓我們在未來依月份輕鬆存取總銷售額。

  1. 在 [ 首頁] 索引標籤上,選取 [ 新增 SQL 查詢]。

    Screenshot of New SQL query from the home tab.

  2. 在查詢編輯器中,複製並貼上或輸入下列查詢,以遞減順序計算每月總銷售額。 輸入之後,選取 [ 執行 ] 以檢視結果。

    SELECT 
    MONTH(DateKey) as "MonthNumber",
    SUM(SalesAmount) as "TotalSalesAmount"
    FROM FactOnlineSales
    GROUP BY MONTH(DateKey)
    

    Screenshot of SQL query editor.

  3. 反白顯示完整查詢文字,然後選取 [ 另存新檔] 檢視

    Screenshot of Save as view option.

  4. 在 [另存新檔] 檢視視窗中,將 [檢視名稱 ] 設定為 TotalSalesByMonth ,然後選取 [ 確定]。

    Screenshot of Save as view window.

  5. 在 [總管] 中,展開 [檢視] 區段,然後選取 [TotalSalesByMonth] 以在 [數據預覽] 中檢視結果。

    Screenshot of Views with the Lakehouse explorer.

    完成探索 SQL 端點編輯器之後,您可以返回工作區,繼續進行本教學課程的下一節。

    Screenshot of the side rail and selection of the workspace.

自動建立報表

既然您已建立數據模型,就可以使用快速建立來可視化和探索您的數據。


  1. 在工作區檢視中,將滑鼠停留在專案類型 [數據集] 和 專案名稱 SalesLakehouse 上方。 選取省略號 (... ), 然後選擇 [ 自動建立報表]。

    Screenshot of the Autocreate report option with a workspace.

    報表會自動為您產生,並根據 [您的數據] 窗格中的數據行選取項目動態更新。

    • 顯示的報表可能與下圖不同。

    Screenshot of the finished Auto-create report.

  2. 從功能區選取 [ 儲存 ] 以將複本儲存至目前的工作區

    • 若要輸入完整的視覺效果撰寫體驗,您可以在功能區上選取 [ 編輯 ]。

    Screenshot of the Save button when visualizing data.

  3. 在 [儲存報表] 對話框中,於 [輸入報表字段的名稱] 中輸入 [銷售摘要]。 完成之後,選取 [ 儲存 ]。

    Screenshot of the Save button completing its process when visualizing data.

您可以深入瞭解 快速建立

恭喜您完成教學課程! 如果您已建立本教學課程的工作區,您可以選擇立即將其刪除。 或者,您可以移除教學課程期間建立的個別專案。

我們希望本教學課程示範 Power BI 使用者如何使用 Microsoft Fabric 輕鬆地提供任何層級數據的深入解析。