How to check in powerquery, if an entire table contains the search value in any column or any row. Say we have a table:
+------------+-----------+---------+
| column1 | column2 | column3 |
+------------+-----------+---------+
| apple | banana | cherry |
| damson | entawak | fig |
| watermelon | wolfberry | plum |
+------------+-----------+---------+
I want to find in which column and a row there is wolfberry
? It is c=2 and r=3. I would like to use the coordinates for further data processing.
Here is a code of sample table for your convenience:
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"
You may use following technique:
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