使用 text.contains Power BI 的 Merqe 查询

Merqe Queries with text.contains Power BI

我必须要合并的查询。

这是我要比较的两个示例列。

我需要从第一个列表中的第二个列表中找到字符串。如果有匹配项,则将包含匹配字符串的列表附加到第一个列表。

这些列表来自两个不同的查询

Those lists are from two different queries

没关系,您可以使用其名称引用另一个查询。这可能是下面的 Source1Source2

need to find the string from the second list, in the first on append a list with the matching string to the first list.

我不确定你的意思是不是

forall B in A =>
    Text.Combine( {_} & {A}, "_")

我以为你的意思是积累一个列表,我就是这么做的。

let
    json1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wysw1NjIxNTMz0isoKlGK1QGJmJqhiiQnlsRD1SGpAvLj0TSiG1Wc9mH+hI1pWUBxHCowLcNqEUF7oBJA67YZG5sCqQ7jrDSIfCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [File = _t]),
    Source1 = Table.TransformColumnTypes(json1,{{"File", type text}}),

    json2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkzLyjEyNskyVYrViVYyNjKBMMzMjMD0h/kTtsEYHWBGZi6YgqlTio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Substring = _t]),
    Source2 = Table.TransformColumnTypes(json2,{{"Substring", type text}}),

    /*
    find all matching values in the source text
    then merge the matching values with separator
    
    optional params with defaults:
    
        separator: string to join on, "_" by default
        comparer: case sensitivity, off by default
    */
    SummarizeMatchingText = (source as text, patterns as list, optional options as nullable record) as any =>
        let             
            separator = options[separator]? ?? "_",
            comparer = options[comparer]? ?? Comparer.OrdinalIgnoreCase,
            select_matching = List.Select(
                patterns,
                (item) =>
                    Text.Contains( source, item, comparer)
            ),
            merged = Text.Combine( select_matching, separator)            
        in 
            merged,

    col_matches = Table.AddColumn(
        Source1, 
        "Matches",
        (row) =>
            SummarizeMatchingText(
                row[File], Source2[Substring],
                [ separator = "—" ]
            ),
        Text.Type
    ),

    // summarize multiple steps
    Summary = [
        Source1 = Source1,
        Source2 = Source2,
        col_matches = col_matches,
        expectEmpty = SummarizeMatchingText(
            "sffj324", Source2[Substring]  ),

        expectMatch = SummarizeMatchingText(
            "cat_im32456.prt", Source2[Substring]  )
    ],
    col_matches1 = Summary[col_matches]
in
    col_matches1