條件函式

Alteryx 的資料轉換

Josh Honken

Senior Associate at Knowesis

課程導覽與歡迎

資料轉換圖示

  • 第 1 章: Formula 工具
  • 第 2 章: Transpose 工具
  • 第 3 章: Cross Tab 工具
Alteryx 的資料轉換

Formula 工具

Alteryx 軟體中的 Formula 工具藍色圖示。圖示為實驗室裡的冒泡燒杯。

  • 建立新欄位
  • 更新欄位
  • 進行計算與運算

$$ $$ $$ 你可以用來:

  • 套用條件判斷
  • 格式化日期
  • 進行數學計算
Alteryx 的資料轉換

函式與運算子

條件函式: 以條件檢驗資料

  • IFELSEIF
  • IIF

邏輯運算子: 組合敘述,提升複雜度

  • AND (&&)
  • OR (||)
  • NOT (!)
Alteryx 的資料轉換

IF 敘述

  • 語法: IF c THEN t ELSE f ENDIF
  • 若條件 c 為真回傳 t,否則回傳 f

美國地圖,輕微標示四個參考州

Alteryx 的資料轉換

IF 敘述

  • 語法: IF c THEN t ELSE f ENDIF
  • 若條件 c 為真回傳 t,否則回傳 f

$$

State Region
Texas
California
Indiana
New York

美國地圖,輕微標示四個參考州

Alteryx 的資料轉換

IF 敘述

  • 語法: IF c THEN t ELSE f ENDIF
  • 若條件 c 為真回傳 t,否則回傳 f
  • IF [State] = 'TX' THEN 'South' ELSE 'Not South' ENDIF $$
State Region
Texas South
California Not South
Indiana Not South
New York Not South

美國地圖,突顯德州

legend.png

Alteryx 的資料轉換

IIF 函式

  • bool 為真回傳 x,否則回傳 y
  • 語法: IIF(bool, x, y)
  • IIF([State] = 'TX', 'South', 'Not South'

$$

State Region
Texas South
California Not South
Indiana Not South
New York Not South

美國地圖,突顯德州

legend.png

Alteryx 的資料轉換

ELSEIF 敘述

  • 若第一個條件 c 為真則回傳 t
  • 否則若第二個條件 c2 為真則回傳 t2
  • 否則回傳 f

IF c THEN t ELSEIF c2 THEN t2 ELSE f ENDIF

IF [State] = 'TX' THEN 'South' ELSEIF [State] = 'CA' THEN 'West' ELSE 'Other' ENDIF

State Region
Texas South
California West
Indiana Other
New York Other

elseifmap.png

Alteryx 的資料轉換

IF 敘述中的多重條件

  • AND (&&):兩個條件都為真才為真
  • OR (||):任一條件為真即為真
  • NOT (!):條件為假則為真

IF [State]='Texas' AND [City]='Dallas' OR [State]='Texas' AND [City]='Fort Worth' THEN 'Dallas Fort Worth' $$ ELSE 'No match' ENDIF

State City Dallas Texas?
Texas Dallas Dallas Fort Worth
Arkansas Dallas City matches but not state
Texas Fort Worth Dallas Fort Worth
California San Francisco No match
Alteryx 的資料轉換

CONTAINS()

  • CONTAINS(String, Target)
  • CONTAINS([Customer Name],'z')
Customer Name
Claire Gute
Sean O'Donnell
Pete Kriz
Zachary Taylor
Alteryx 的資料轉換

CONTAINS()

  • CONTAINS(String, Target)
  • CONTAINS([Customer Name],'z')
Customer Name Contains Z?
Claire Gute 0
Sean O'Donnell 0
Pete Kriz -1
Zachary Taylor -1
Alteryx 的資料轉換

本課資料集

本課程的資料集是:Genesis_LLC_Company_HR_Data.xlsx

Age Attrition BusinessTravel DailyRate
51 0 -1 684
52 0 0 699
42 0 0 532
47 0 0 359

本課程使用的模擬公司 Genesis 研發標誌

Alteryx 的資料轉換

一起來練習吧!

Alteryx 的資料轉換

Preparing Video For Download...