Catalin,
How about the questions on not showing the invoked function in the queries list ? that is under the Text (optional) enter a text then click involve, it will generate a query in the query listing, I do not want PQ to generate, is it possible
and for this function, is zit possible to search multiple and return multiple results
for e.g. //Level/Camp CC/Tuckshop
the lookup table Camp CC = C, Tuckshop = Canteen
the result will be
//Level/Camp CC/Tuckshop D
//Level/Camp CC/Tuckshop Canteen
See attached
Thank you !
Catalin Bombea said
First, I add the lookup table as a query, just like any other table, ad I perform the operations I need to get the result I need: added a column with a simple formula to check if my custom text is in the Camp column, filter out false matches, remove other columns than "Region".Only at this point I open the advanced editor, find below in red the only changes I made to convert the query to a function that takes a text variable:
<br />
<span style="color: #ff0000;"> (Text)=></span><br />
let<br />
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],<br />
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Camp", type text}, {"Region", type text}}),<br />
#"Added Custom" = Table.AddColumn(#"Changed Type", "Match", each Text.Contains(<span style="color: #ff0000;">Text</span>,[Camp])),<br />
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Match] <> false)),<br />
#"Removed Other Columns" = <span style="color: #ff0000;">try</span> Table.SelectColumns(#"Filtered Rows",{"Region"})<span style="color: #ff0000;">{0} otherwise null</span><br />
in<br />
#"Removed Other Columns"<br />
<br />The (Text)=> part is what makes it a function, you just need to place that above the existing query.
To add more keywords, just add them to the lookup table from sheet, there is nothing else you need to do in query, it will just read the updated table.
The rows with no match will display null in both query editor and result table.
what is the original word for Text (highlighted in red) ? I am trying to understand your code from #Added custom to Removed other columns, you mentioned you use the Power query UI
or can you provide me the original code before amending to function i.e. replace add code (those in red)
Thank you
If you want to have multiple matches, remove the {0} from the function, this is what refers to the first match only.
When you work on the lookup table, you can use any text you want to add the custom column.
You can use any static text you want, "Camp AB" for example:
#"Added Custom" = Table.AddColumn(#"Changed Type", "Match", each Text.Contains("Camp AB",[Camp])),
Then, after you're done with the processing, add the parameter you want above the first line of the query:
(ParameterName)=>
and replace "Camp AB" with ParameterName.
I used Text as parameter name.
Hi Catalin
but when I remove the {0}, all shown error
Hi Catalin,
Attached, how to return in this format, possible ?
Description of text verbatim | Region |
//Level 1/Camp ABC/Bunk | A |
//Level 1/Camp DD/Tuckshop | D |
//Level 1/Camp DD/Tuckshop | Canteen |
There is a pipe burst in Camp BB | B |
d:folder1CampCampAB | C |
----------- Camp CC ……………….. | D |
Indeed, the last step of the query returns error, because {0} in the function return the result as a record typ.
If we remove {0} from function, we need to also replace the last step of the query, because the result will be a table, not a record anymore. I basically removed the last expand step, and I expanded the column again using UI.
Wow Catalin, fantastic, basically this function is so powerfully can practically extract any key words in a phrases
I am so grateful your patience in sharing to me your coding
If in summary, Table.ExpandTableColumn can display multiple match (as removing {0} and display in a table (many lines), however, Table.ExpandRecordColumn only the 1st match (0), 2nd match {1} and so on from a phrase
Appreciate your kindness
Chris Yap