共用方式為


Table.FuzzyJoin

語法

Table.FuzzyJoin(
    table1 as table,
    key1 as any,
    table2 as table,
    key2 as any,
    optional joinKind as nullable number,
    optional joinOptions as nullable record
) as table

關於

根據 table1 (for table2) 和 key1 (for table1) 所選取的索引鍵資料行值進行模糊比對,將 key2 的資料列與 table2 的資料列聯結。

模糊比對的比較是根據文字相似度,而不是文字相等度。

根據預設,會執行內部聯結,但可能會納入選擇性的 joinKind 來指定聯結類型。 這些選項包括:

可以選擇加入一個joinOptions 集合,以指定如何比較鍵欄。 這些選項包括:

  • ConcurrentRequests:介於 1 到 8 之間的數字,指定要用於模糊比對的平行執行緒數目。 預設值是 1。
  • Culture:允許根據文化特性特定規則來比對記錄。 可以是任何有效的文化名稱。 例如,文化特性 (Culture) 選項 'ja-JP',會依據日文文化特性來比對記錄。 預設值為 "",這會根據不變性英文文化進行匹配。
  • IgnoreCase:允許不區分大小寫金鑰比對的邏輯 (true/false) 值。 例如,當為 true 時,"Grapes" 與 "grapes" 相符。 預設值為 True。
  • IgnoreSpace:邏輯值(true/false),用於結合文字部分以尋找相符項目。 例如,當值為 true 時,"Gra pes" 與 "Grapes" 相符。 預設值為 True。
  • NumberOfMatches:整數,指定可針對每個輸入資料列傳回的相符資料列數目上限。 例如,值 1 會針對每個輸入資料列傳回最多一個相符資料列。 如果未提供此選項,則會傳回所有相符的資料列。
  • SimilarityColumnName:資料行的名稱,這個資料行會顯示輸入值與該輸入代表值之間的相似性。 預設值為 Null,在這種情況下,將不會新增相似的新資料行。
  • Threshold:介於 0.00 和 1.00 之間的數字,指定兩個值相符的相似性分數。 例如,只有在此選項設為 0.90 以下時,"Grapes" 和 "Graes" (缺少 "p") 才會相符。 閾值 1.00 只允許完全相符。 (請注意,模糊的「完全相符」可能會忽略大小寫、文字順序和標點符號等差異。)預設值為 0.80。
  • TransformationTable:資料表,允許根據自訂值對應來比對記錄。 應該包含 "From" 和 "To" 欄位。 例如,若轉換資料表中提供包含 "Grapes" 的 "From" 資料行及包含 "Raisins" 的 "To" 資料行,則 "Grapes" 會與 "Raisins" 相符。 請注意,轉換會套用至轉換資料表中所有出現的文字。 使用上述的轉換資料表,"Grapes are sweet" 也會視為與 "Raisins are sweet" 相符。

範例 1

根據 [FirstName] 對兩個資料表進行內部模糊聯結

使用方式

Table.FuzzyJoin(
    Table.FromRecords(
        {
            [CustomerID = 1, FirstName1 = "Bob", Phone = "555-1234"],
            [CustomerID = 2, FirstName1 = "Robert", Phone = "555-4567"]
        },
        type table [CustomerID = nullable number, FirstName1 = nullable text, Phone = nullable text]
    ),
    {"FirstName1"},
    Table.FromRecords(
        {
            [CustomerStateID = 1, FirstName2 = "Bob", State = "TX"],
            [CustomerStateID = 2, FirstName2 = "bOB", State = "CA"]
        },
        type table [CustomerStateID = nullable number, FirstName2 = nullable text, State = nullable text]
    ),
    {"FirstName2"},
    JoinKind.LeftOuter,
    [IgnoreCase = true, IgnoreSpace = false]
)

輸出

Table.FromRecords({
    [
        CustomerID = 1,
        FirstName1 = "Bob",
        Phone = "555-1234",
        CustomerStateID = 1,
        FirstName2 = "Bob",
        State = "TX"
    ],
    [
        CustomerID = 1,
        FirstName1 = "Bob",
        Phone = "555-1234",
        CustomerStateID = 2,
        FirstName2 = "bOB",
        State = "CA"
    ],
    [
        CustomerID = 2,
        FirstName1 = "Robert",
        Phone = "555-4567",
        CustomerStateID = null,
        FirstName2 = null,
        State = null
    ]
})