如何在Powerquery

时间:2019-05-22 08:50:58

标签: powerbi powerquery m

如何在powerquery中检入整个表是否在任何列或任何行中包含搜索值。说我们有一张桌子:

+------------+-----------+---------+
|  column1   |  column2  | column3 |
+------------+-----------+---------+
| apple      | banana    | cherry  |
| damson     | entawak   | fig     |
| watermelon | wolfberry | plum    |
+------------+-----------+---------+

我想找到wolfberry在哪一列和哪一行?它是c = 2和r = 3。我想将坐标用于进一步的数据处理。

为方便起见,这里是示例表的代码:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSiwoyElV0lFKSswDQiAjOSO1qKhSKVYnWiklMbc4Pw8olppXkliemH1oAZCdlpkOlixPLEktyk3NASsoz89JSwLr01EqyCnNVYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}})
in
    #"Changed Type"

1 个答案:

答案 0 :(得分:2)

您可以使用以下技术:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSiwoyElV0lFKSswDQiAjOSO1qKhSKVYnWiklMbc4Pw8olppXkliemH1oAZCdlpkOlixPLEktyk3NASsoz89JSwLr01EqyCnNVYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    func = (word) =>
            [r = Table.AddIndexColumn(Source, "r", 1, 1),
             c = Table.AddIndexColumn(Table.Transpose(Source), "c", 1, 1),
             coordinates = [r = Table.FindText(r, word)[r]{0}, c = Table.FindText(c, word)[c]{0}]
            ][coordinates],
    search = func("wolfberry")
in
    search