Hi Power Query Guru
See attached, is there a way to search text or phrases from another List and return the values
in excel need to use
=IFERROR(LOOKUP(2^15,SEARCH('Contents Lib'!$A$2:$A$8,A2),'Contents Lib'!$B$2:$B$8),"")
and is tedious
thank you
Hi Chris,
Yes, you can extract the camp from the text string and then use Merge Tables to bring in the Region column. See example attached.
Mynda
Hi Mynda,
Thanks, this is for delimited that are consistent throughout
in my real case scenario, the description can be free form see attached (illustration)
is there a equivalent excel array in Power Query or there are other simple way (using M language)
Hi Mynda,
what version of excel you are using
= Table.AddColumn(#"Changed Type", "Text Between Delimiters", each Text.BetweenDelimiters([Folder path], "/", "/", 2, 0), type text)
my excel 2016 don't have the Text Between Delimiters option, mine office is professional plus 2016
Hi Chris,
I'm using Office 365. You can try updating your version of Excel to see if you get the new functions.
In regards to your messy data. Even with formulas there are limits. CampAB without a space will not be found because it doesn't exist in your Camp Regions table.
For the other data, you could split it by 'Camp' as the delimiter and then remove the text after the last forward slash and the .... and then do a merge on the Camp name. It's all possible, except for the CampAB without the space.
Mynda
Hi Mynda,
Actually, the actual datasets are proj description and was trying to do text analytics, and there is a table (List) that store all the translation, for e.g. if Camp A - Fleet Department
In the past I use combination of few excel commands
=IFERROR(LOOKUP(2^15,SEARCH('Contents Lib'!$A$2:$A$8,A2),'Contents Lib'!$B$2:$B$8),"")
$A$2:$A$8 = Camp AA, Camp BB ..... (this one will grow)
$B$2:$B$8 = 2nd column that returning back for analysis
Therefore, I was wondering is there a better way to use M language combine with PQ editor features to ease user's experience haha, as for using delimiter need to build a lot of scenario as we wouldn't know the pattern of the data input from users (free play), those are legacy system fields
Thank you
This thread might give you some ideas. You'll still need to fix any data that doesn't conform to your list e.g. CampAB without the space.
Hi Chris,
You can transform the lookup table query into a function, after adding a new column to check for a match on each row.
Note that there cannot be perfect matches, as for example //Level 1/Camp ABC/Bunk can match with Camp ABC -region A but also with Camp AB-region C.
The solution from the attached file will take only the first match in such cases.
You might be able to deal with such cases if your lookup table contains values in this format:
/Camp ABC/
/Camp AB/
thank you so much Mynda for your tips
as for the CampAB without space, user will need to constantly update their library
Thank you so much Catalin, this is the first time I see function and parameter in PQ, after adding CampAB = C and refresh it returns correctly, amazing !!!
Can I confirm your function will look out any key words, phrases in the matching table and return column 2 for any form of verbatim texts
Thank you !!
Well, that's what your test just did, if the keyword is in lookup table, there will be a value return, it will display null if no match found.
It is case sensitive, so you have to be careful with text case, or make the query case insensitive to make it work with "Camp AB" and "camp ab" as well.
As mentioned before, if there are multiple matches, only the first will be returned. It is possible though to return a list of all matches in this case, like "A, C, D" if there are 3 matches for example.
Hi Catalin
for the match function, you are using Advanced editor to input M code directly right, or UI ?
= (Text)=>
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Camp", type text}, {"Region", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Match", each Text.Contains(Text,[Camp])),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Match] <> false)),
#"Removed Other Columns" = try Table.SelectColumns(#"Filtered Rows",{"Region"}){0} otherwise null
in
#"Removed Other Columns"
which line should I amend if I want to expand my table 2 to include other keywords other than Camp **
and each time we entered an invalid text it will involve the result in the query listing, can we just display out it is null at the preview area ?
Sorry to ask so many questions, all along i was no good in coding 🙁
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:
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Camp", type text}, {"Region", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Match", each Text.Contains(Text,[Camp])),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Match] <> false)),
#"Removed Other Columns" = try Table.SelectColumns(#"Filtered Rows",{"Region"}){0} otherwise null
in
#"Removed Other Columns"
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.
Hi catalin,
so each time I append new phrases and the result, the function code will automatically update right ?
Yes.