mixmatch - 指令碼與圖表函數
mixmatch 函數會比較第一個參數與所有後續參數,並傳回相符的運算式數字位置。比較不區分大小寫。
語法:
mixmatch( str, expr1 [ , expr2,...exprN ])
提示備註如果您想要使用區分大小寫的比較,請使用 match 函數。如果您想要使用不區分大小寫的比較及萬用字元,請使用 wildmatch 函數。
以下表格中的第一個運算式會傳回 0 代表 Stockholm,因為 'Stockholm' 不包括在 mixmatch 函數的運算式清單中。這會傳回 4 代表 'Zurich',因為 mixmatch 比較區分大小寫。
Cities | mixmatch( Cities,'Toronto','Boston','Beijing','Zurich') | mixmatch( Cities,'Toronto','Boston','Beijing','Stockholm','Zurich') |
---|---|---|
北京 |
3 |
3 |
波士頓 | 2 | 2 |
斯德哥爾摩 | 0 | 4 |
多倫多 | 1 | 1 |
蘇黎世 | 4 | 5 |
您可以使用混合相符項目,以執行運算式的自訂排序。
按照預設,會按數字或字母排序欄,視資料而定。
Cities |
---|
北京 |
波士頓 |
斯德哥爾摩 |
多倫多 |
蘇黎世 |
若要變更順序,請進行下列事項:
- 在屬性面板中開啟圖表的排序區段。
- 對於您要進行自訂排序的欄,關閉自動排序。
- 取消選取按數字排序和按字母排序。
-
選取按運算式排序,然後輸入類似下列項目的運算式:
=mixmatch( Cities, 'Toronto','Boston','Beijing','Stockholm','Zurich')
Cities 欄的排序順序會變更。
城市 |
---|
多倫多 |
波士頓 |
北京 |
斯德哥爾摩 |
蘇黎世 |
您也可以檢視傳回的數值。
城市 | Cities & ' - ' & mixmatch ( Cities, 'Toronto','Boston', 'Beijing','Stockholm','Zurich') |
---|---|
多倫多 | 多倫多 - 1 |
波士頓 | 波士頓 - 2 |
北京 | 北京 - 3 |
斯德哥爾摩 | 斯德哥爾摩 - 4 |
蘇黎世 | 蘇黎世 - 5 |
載入指令碼
您可以使用 mixmatch 載入資料子集。例如,您可以傳回函數中運算式的數值。然後您可以限制根據數值載入的資料。若沒有相符項目,Mixmatch 會傳回 0。在此範例中相符的所有運算式將會因此傳回 0,並且將會按照 WHERE 陳述式從資料載入中排除。
在資料載入編輯器中,建立名為 Load 的新區段,然後新增下列內容:
Load * Inline [
transaction_id, transaction_date, transaction_amount, transaction_quantity, customer_id, size, color_code
3750, 20180830, 23.56, 2, 2038593, L, Red
3751, 20180907, 556.31, 6, 203521, m, orange
3752, 20180916, 5.75, 1, 5646471, S, blue
3753, 20180922, 125.00, 7, 3036491, l, Black
3754, 20180922, 484.21, 13, 049681, xs, Red
3756, 20180922, 59.18, 2, 2038593, M, Blue
3757, 20180923, 177.42, 21, 203521, XL, Black
];
/*
Create new table called Transaction_Buckets
Create new fields called Customer, and Color code - Black, Blue, blue
Load Transactions table.
Mixmatch returns 1 for 'Black', 2 for 'Blue'.
Also returns 3 for 'blue' because mixmatch is not case sensitive.
Only values that returned numeric value greater than 0
are loaded by WHERE statement into Transactions_Buckets table.
*/
Transaction_Buckets:
Load
customer_id,
customer_id as [Customer],
color_code as [Color Code - Black, Blue, blue]
Resident Transactions
Where mixmatch(color_code,'Black','Blue') > 0;
結果
色彩代碼黑色,藍色,藍色 | 客戶 |
---|---|
黑色 | 203521 |
黑色 | 3036491 |
藍色 | 2038593 |
藍色 | 5646471 |