自訂欄位

Excel 中級 Power Query

Lyndsay Girard

Performance Analytics Consultant

M 公式語言

  • 簡稱「M」(代表 Data Mashup)
  • Power Query 的函數式程式語言
  • 區分大小寫
  • 內建函式豐富

在筆電上寫程式

Excel 中級 Power Query

產生 M 程式碼

  • 作用於每個查詢步驟的幕後程式碼
    • 自動產生
  • 可檢視 M 程式碼:
    • 公式列
    • 進階編輯器

公式列: Ch2_Formula_Bar.png

進階編輯器: Ch2_Advanced_Editor.png

Excel 中級 Power Query

自訂欄位

  • 使用者自訂的計算欄位
  • 以 M 語言撰寫
  • 可擴充內建轉換功能
    • 巢狀條件邏輯
    • 進階索引
    • 複雜計算

Ch2_Custom_Column_Ribbon_Screenshot.png

Excel 中級 Power Query

巢狀條件邏輯

  • 參照欄位與值
  • 可包含多層條件判斷
    • If... Then... Else 陳述式
  • 可搭配邏輯運算子
    • AND
    • OR

基本條件邏輯

if age >= 65  
    and arrivalmode = "Car"
    then "group1"
else "group2"
Excel 中級 Power Query

巢狀條件邏輯

  • 參照欄位與值
  • 可包含多層條件判斷
    • If... Then... Else 陳述式
  • 可搭配邏輯運算子
    • AND
    • OR

自訂條件邏輯

if age >= 65 and age <= 80
    and arrivalmode = "Car" 
   then "group1" 
    else if age >= 65 and age <= 80
    and arrivalmode = "ambulance" 
   then "group1a"
else "group2"
Excel 中級 Power Query

進階索引

Ch2_Before_Groupby_AllRows.png

  • 依定義的群組產生自訂索引或排名
Excel 中級 Power Query

進階索引

Ch2_Before_Groupby_AllRows_SimpleIndex.png

  • 依定義的群組產生自訂索引或排名
    • 簡易索引
Excel 中級 Power Query

進階索引

Ch2_Before_Groupby_AllRows_GroupedIndex.png

  • 依定義的群組產生自訂索引或排名
    • 進階索引(群組內)
Excel 中級 Power Query

進階索引

Ch2_GroupBy_Aggregation.png

  • 依定義的群組產生自訂索引或排名
  • 使用「All Rows」彙總的群組依據作業
Excel 中級 Power Query

進階索引

Ch2_GroupBy_AllRows.png

  • 依定義的群組產生自訂索引或排名
  • 使用「All Rows」彙總的群組依據作業
  • 搭配自訂 M 資料表函式
    Table.AddIndexColumn
    
Excel 中級 Power Query

一起來練習吧!

Excel 中級 Power Query

Preparing Video For Download...