I am in need of help finding 5+ character patterns between 2 cells in the same worksheet.
I found information online to set up an example code and I thought I would be able to tweak it to fix but is not working. Can anyone help me?
Here is what I am hoping to achieve:
Here is the formula I put into column C:
=Regexpmatch(A1:B1,"^[\S]{5}")
And the code in Visual Basic: Module1(Code)
Public Function RegExpMatch(input_range As Range, pattern As String, Optional match_case As Boolean = True) As Variant
Dim arRes() As Variant 'array to store the results
Dim iInputCurRow, iInputCurCol, cntInputRows, cntInputCols As Long 'index of the current row in the source range, index of the current column in the source range, count of rows, count of columns
On Error GoTo ErrHandl
RegExpMatch = arRes
Set regEx = CreateObject("VBScript.RegExp")
regEx.pattern = pattern
regEx.Global = True
regEx.MultiLine = True
If True = match_case Then
regEx.ignorecase = False
Else
regEx.ignorecase = True
End If
cntInputRows = input_range.Rows.Count
cntInputCols = input_range.Columns.Count
ReDim arRes(1 To cntInputRows, 1 To cntInputCols)
For iInputCurRow = 1 To cntInputRows
For iInputCurCol = 1 To cntInputCols
arRes(iInputCurRow, iInputCurCol) = regEx.Test(input_range.Cells(iInputCurRow, iInputCurCol).Value)
Next
Next
RegExpMatch = arRes
Exit Function
ErrHandl:
RegExpMatch = CVErr(xlErrValue)
End Function
Sub Run()
End Sub
I put this formula into Column C and received results in both Columns C and D. However, I cannot tell what it is even pulling as all the values in Column C are TRUE and I see no pattern or reason to why I received the FALSEs where I did.
Your regex pattern will only return a match based on the first five non-space characters in the string.
It seems to me that what you really want to do is return TRUE if there are matching Words in the two strings, and if those words are five or more characters in length.
If that is not the case, please clarify.
Split each string into a list or array of Words
For Column1, a Word is separated by #, ., or the transition from lower case to upper case letters.
For Column 2, a Word is separated by a Space
Filter each list to only retain words containing five or more characters
Check to see if a word is present in both lists.
This can be done using VBA and/or Power Query.
Here is a Power Query solution:
Power Query is available in Windows Excel 2010+ and Excel 365 (Windows or Mac)
To use Power Query
Select some cell in your Data Table
Data => Get&Transform => from Table/Range
When the PQ Editor opens: Home => Advanced Editor
Make note of the Table Name in Line 2
Paste the M Code below in place of what you see
Change the Table name in line 2 back to what was generated originally.
Read the comments and explore the Applied Steps to understand the algorithm
M Code
let
//Change next line to reflect actual data source
Source = Excel.CurrentWorkbook(){[Name="Table21"]}[Content],
//Set the data types
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
//Add custom column
#"Added Custom" = Table.AddColumn(#"Changed Type", "Match", each
let
/*Split column 1 by
Transition from lower case to upper case character.
Then by `#` or `.`
Filter to include only words with five or more characters*/
#"Split Col1" =
List.Select(
List.Combine(
List.Transform(
Splitter.SplitTextByCharacterTransition({"a".."z"},{"A".."Z"})([Column1]),
each Text.SplitAny(_,"#."))), each Text.Length(_)>=5),
/*Split Column 2 by <space>
Filter to include only words with length >=5*/
#"Split Col2" =
List.Select(
Text.Split([Column2]," "),
each Text.Length(_)>=5),
/*Create a List of words that are in both of the above lists
If there are one or more words in the Intersection of the two lists
then True, else False*/
Match =
List.Intersect(
{#"Split Col1",#"Split Col2"},Comparer.OrdinalIgnoreCase)
in
List.Count(Match) > 0, type logical)
in
#"Added Custom"
Seems like you could try:
Formula in C1:
=LET(x,TEXTSPLIT(B1," "),SUM(IFERROR(SEARCH(LEFT(FILTER(x,LEN(x)>4),5),A1),))>0)
Related
In the Excel Power Query Editor, I have a field whose values I'm converting. The code looks like this
if [Field] = "a" then "abcd" else if [Field] = "b" then "efg"
else if [Field]=" " then " "
The problem is that [Field] could have just 2 spaces, like this " ", and I want to keep those two spaces, but when I see that field in a pivot table the spaces are gone and the field value is essentially blank. Pivot tables seem to trim the field's value. How can I prevent that trimming so that the two-space value is retained?
The ANSI character code 160 can do this for you. AKA "the evil char", sometimes cheats us by insisting on being where it shouldn't be (in place of a blank). Then create a variable called, say, CharCode160, and assign the character Chr(160) to it. This is the M code to guide you through your solution.
Please note that the source table is named "Table1" and the field involved has the column title "TheField".
It will be useful to add a routine - or modified code - that counts how many blanks there are in the field, to make the correct replacement.
let
CharCode160 = Character.FromNumber(160),
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"TheField", type text}}),
#"Conditional Column Added" = Table.AddColumn(#"Changed Type", "Custom", each if [TheField] = "a" then "abcd" else if [TheField] = "b" then "efg" else if [TheField] = " " then CharCode160 & CharCode160 else null)
in
#"Conditional Column Added"
If character does not necessarily need to be space character then you could use other unicode characters that look like space:
https://www.compart.com/en/unicode/category/Zs
For example: https://www.compart.com/en/unicode/U+2000
You just copy character and paste it to PQ.
I have 2 Excel data sets each comprising a column of word patterns and have been searching for a way to copy and group all instances of repetition within these columns into a new column.
This is the closest result I could find so far:
Sub Common5bis()
Dim Joined
Set d = CreateObject("Scripting.Dictionary") 'make dictionary
d.CompareMode = 1 'not case sensitive
a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value 'data to array
For i = 1 To UBound(a) 'loop trough alle records
If Len(a(i, 1)) >= 5 Then 'length at least 5
For l = 1 To Len(a(i, 1)) - 4 'all strings withing record
s = Mid(a(i, 1), l, 5) 'that string
d(s) = d(s) + 1 'increment
Next
End If
Next
Joined = Application.Index(Array(d.Keys, d.items), 0, 0) 'join the keys and the items
With Range("D1").Resize(UBound(Joined, 2), 2) 'export range
.EntireColumn.ClearContents 'clear previous
.Value = Application.Transpose(Joined) 'write to sheet
.Sort .Range("B1"), xlDescending, Header:=xlNo 'sort descending
End With
End Sub
Which yielded this result for the particular question:
This example achieves 4 of the things I'm trying to achieve:
Identify repeating strings within a single column
Copies these strings into a separate column
Displays results in order of occurrence (in this case from least to most)
Displays the quantity of repetitions (including the first instance) in an adjacent column
However, although from reading the code there are basic things I've figured out that I can adapt to my purposes, it still fails to achieve these essential tasks which I'm still trying to figure out:
Identify individual words rather than single characters
I could possibly reduce the size from 5 to 3, but for the word stings I have (lists of pronouns from larger texts) that would include "I I" repetitions but won't be so great for "Your You" etc, whilst at least 4 or 5 would miss anything starting with "I I"
Include an indefinite amount of values - looking at the code and the replies to the forum it comes from it looks like it's capped at 5, but I'm trying to find a way to identify all repetitions for all multiple word strings which could be something like "I I my you You Me I You my"
Is case sensitive - this is quite important as some words in the column have been capitalised to differentiate different uses
I'm still learning the basics of VBA but have manually typed out this example of what I'm trying to do with the code I've found above:
Intended outcome:
And so on
I'm a bit screwed at this point which is why I'm reaching out here (sorry if this is a stupid question, I'm brand new to VBA as my work almost never needs Excel, let alone macros) so will massively appreciate any constructive advice towards a solution!
Because I've been working with it recently, I note that you can obtain your desired output using Power Query, available in Windows Excel 2010+ and Office 365 Excel
Select some cell in your original table
Data => Get&Transform => From Table/Range or From within sheet
When the PQ UI opens, navigate to Home => Advanced Editor
Make note of the Table Name in Line 2 of the code.
Replace the existing code with the M-Code below
Change the table name in line 2 of the pasted code to your "real" table name
Examine any comments, and also the Applied Steps window, to better understand the algorithm and steps
First add a custom function:
New blank query
Rename per the code comment
Edits to make case-insensitive
Custom Function
//rename fnPatterns
//generate all possible patterns of two words or more
(String as text)=>
let
//split text string into individual words & get the count of words
#"Split Words" = List.Buffer(Text.Split(String," ")),
wordCount = List.Count(#"Split Words"),
//start position for each number of words
starts = List.Numbers(0, wordCount-1),
//number of words for each pattern (minimum of two (2) words in a pattern
words = List.Reverse(List.Numbers(2, wordCount-1)),
//generate patterns as index into the List and number of words
// will be used in the List.Range function
patterns = List.Combine(List.Generate(
()=>[r={{0,wordCount}}, idx=0],
each [idx] < wordCount-1,
each [r=List.Transform({0..starts{[idx]+1}}, (li)=> {li, wordCount-[idx]-1}),
idx=[idx]+1],
each [r]
)),
//Generate a list of all the patterns by using the List.Range function
wordPatterns = List.Distinct(List.Accumulate(patterns, {}, (state, current)=>
state & {List.Range(#"Split Words", current{0}, current{1})}), Comparer.OrdinalIgnoreCase)
in
wordPatterns
Main Function
let
//change next line to reflect data source
//if data has a column name other than "Column1", that will need to be changed also wherever referenced
Source = Excel.CurrentWorkbook(){[Name="Table17"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
//Create a list of all the possible patterns for each string, added as a custom column
#"Invoked Custom Function" = Table.AddColumn(#"Changed Type", "Patterns", each fnPatterns([Column1]), type list),
//removed unneeded original column of strings
#"Removed Columns" = Table.RemoveColumns(#"Invoked Custom Function",{"Column1"}),
//Expand the column of lists of lists into a column of lists
#"Expanded Patterns" = Table.ExpandListColumn(#"Removed Columns", "Patterns"),
//convert all lists to lower case for text-insensitive comparison
#"Added Custom" = Table.AddColumn(#"Expanded Patterns", "lower case patterns",
each List.Transform([Patterns], each Text.Lower(_))),
//Count number of matches for each pattern
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Count", each List.Count(List.Select(#"Added Custom"[lower case patterns], (li)=> li = [lower case patterns])), Int64.Type),
//Filter for matches of more than one (1)
// then remove duplicate patterns based on the "lower case pattern" column
#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Count] > 1)),
#"Removed Duplicates" = Table.Distinct(#"Filtered Rows", {"lower case patterns"}),
//Remove lower case pattern column and sort by count descending
#"Removed Columns1" = Table.RemoveColumns(#"Removed Duplicates",{"lower case patterns"}),
#"Sorted Rows" = Table.Sort(#"Removed Columns1",{{"Count", Order.Descending}}),
//Re-construct original patterns as text
#"Extracted Values" = Table.TransformColumns(#"Sorted Rows",
{"Patterns", each Text.Combine(List.Transform(_, Text.From), " "), type text})
in
#"Extracted Values"
Note that you could readily implement a similar algorithm using VBA, the VBA.Split function and a Dictionary
I would like to move all the comments (Column B3:B14) to be new columns against each unique ID (Column A3:A14).
The Desired Format shows the layout that I would like to get to.
Hopefully that makes sense.
EDIT: This will do what you want using vba:
Option Explicit
Sub TransposeComments()
Dim inSR%, inTR%, inTC%, rgSource As Range, rgTarget As Range
Set rgSource = Range("A3") 'Change this if the 1st ID in the source table is moved
Set rgTarget = Range("D3") 'Change this to start populating at another start point
inTR = -1
Do
If rgSource.Offset(inSR) <> rgSource.Offset(inSR - 1) Then
inTR = inTR + 1: inTC = 2
rgTarget.Offset(inTR) = rgSource.Offset(inSR)
rgTarget.Offset(inTR, 1) = rgSource.Offset(inSR, 1)
Else
rgTarget.Offset(inTR, inTC) = rgSource.Offset(inSR, 1)
inTC = inTC + 1
End If
inSR = inSR + 1
''' End on 1st empty ID (assumes ID's in source data are contiguous and nothing is below them)
Loop Until rgSource.Offset(inSR) = ""
End Sub
I've assumed you know how to implement and call/run the vb. If not, let me know and I try and help with that. :)
============================================================
EDIT: How to do it all with formulas?
I'm unsure of how dynamic the extraction table has to be (as you don't say). For example:
o Will you be making a new extraction each time or will build a standing extractor table
o Will the source data vary in size (so you need to grow and shrink the 'lookup' range)
o Etc.
Given this, I've aimed for a solution that works and is adaptable. I'll leave it to you to adapt as appropriate 😊
To extract the unique serial numbers:
{=IFERROR(INDEX($A$2:$A$14, MATCH(0, COUNTIF($E$2:E2, $A$2:$A$14), 0)),"")}
To extract the corresponding comments:
{=IF($E3="","",IF(SUM(IF($A$2:$A$15=$E3,1))>=COUNTA($F$2:F$2),INDEX($B$2:$B$15,MATCH($E3,$A$2:$A$15,0)+COUNTA($F$2:F$2)-1),""))}
Notice the {}. Both are array formulas (entered with Ctrl, Shift and Enter)
Pictogram:
Addition Information:
The solution proposed assumes any same-serial-numbers are contiguous (as shown in your example.
If that's not the case by default, you'll have to sort the source date so it is.
You can obtain your desired output using Power Query, available in Windows Excel 2010+ and Office 365 Excel
Select some cell in your original table
Data => Get&Transform => From Table/Range
When the PQ UI opens, navigate to Home => Advanced Editor
Make note of the Table Name in Line 2 of the code.
Replace the existing code with the M-Code below
Change the table name in line 2 of the pasted code to your "real" table name
Examine any comments, and also the Applied Steps window, to better understand the algorithm and steps
M Code
let
//read in the data
//change table name in next line to actual table name in your workbook
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
//set data types
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Comments", type text}}),
//group by ID and concatenate the comments with a character not used in the comments
//I used a semicolon, but that could be changed
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {
{"Comment", each Text.Combine([Comments],";")},
//also generate Count of the number of comments in each ID group
//as the Maximum will be the count of the number of columns to eventually create
{"numCols", each Table.RowCount(_)}
}),
//calculate how many columns to create and delete that column
maxCols = List.Max(#"Grouped Rows"[numCols]),
remCount = Table.RemoveColumns(#"Grouped Rows","numCols"),
//Split into new columns
#"Split Column by Delimiter" = Table.SplitColumn(remCount, "Comment",
Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv),maxCols)
in
#"Split Column by Delimiter"
If you have Excel for Microsoft 365 on the Mac with the FILTER and UNIQUE functions, you can use:
D23: =UNIQUE(Table1[ID]) *or some other cell8
and in the adjacent column:
=TRANSPOSE(FILTER(Table1[Comments],Table1[ID]=D23))
Sorry if this is a stupid question but i've been racking my brain for a couple of days now and i can't seem to come up with a solution to this.
I have a list of phrases and a list of keywords that need to be searched, extracted and replaced.
For example i have the following list of keywords in sheet 1 column A that need to be extracted and replaced with the keywords in column B.
red - orange
blue - violet
green - pink
yellow - brown
And in sheet 2 I have a list of phrases in column A.
The girl with blue eyes had a red scarf.
I saw a yellow flower.
My cousin has a red car with blue rims and green mirrors.
And I want to extract in column B the keywords that are matched for every phrase in the exact order that they appear like so:
COLUMN A COLUMN B
The girl with blue eyes had a red scarf. violet, orange
I saw a yellow flower. brown
My cousin has a red car with blue rims and green mirrors. orange, violet, pink
Is there any way this can be achieved either by formula or VBA? Also this needs to be usable with Excel 2016 so i can't use fancy functions like "TEXTJOIN".
Thank you everyone in advance!
Cheers!
L.E.
I was able to find some code that almost does what I need it to do but it does not keep the correct order.
Is there anyway it could be modified to generate the desired results? Unfortunately I'm not that good with VBA. :(
Sub test()
Dim datacount As Long
Dim termcount As Long
datacount = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
termcount = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To datacount
dataa = Sheets("Sheet1").Cells(i, "A").Text
result = ""
For j = 1 To termcount
terma = Sheets("Sheet2").Cells(j, "A").Text
termb = Sheets("Sheet2").Cells(j, "B").Text
If InStr(dataa, terma) > 0 Then
If result = "" Then
result = result & termb
Else
result = result & ", " & termb
End If
End If
Next j
Sheets("Sheet1").Cells(i, "B").Value = result
Next i
End Sub
You can do this with a User Defined Function making use of Regular Expressions.
The worksheet formula:
=matchWords(A2,$K$2:$L$5)
where A2 contains the sentence, and the second argument points to the translation table (which could be on another worksheet).
The code
Option Explicit
Function matchWords(ByVal s As String, translTbl As Range) As String
Dim RE As Object, MC As Object, M As Object
Dim AL As Object 'collect the replaced words
Dim TT As Variant
Dim I As Long
Dim vS As Variant
'create array
TT = translTbl
'initiate array for output
Set AL = CreateObject("system.collections.arraylist")
'initiate regular expression engine
Set RE = CreateObject("vbscript.regexp")
With RE
.Global = True
.ignorecase = True 'could change this if you want
.Pattern = "\w+" 'can change this if need to include some non letter/digit items
'split the sentence, excluding punctuation
If .test(s) Then
Set MC = .Execute(s)
For Each M In MC
For I = 1 To UBound(TT, 1)
If M = TT(I, 1) Then AL.Add TT(I, 2)
Next I
Next M
End If
End With
matchWords = Join(AL.toarray, ", ")
End Function
I would suggest you use Power Query which is a built-in function since Excel 2013.
Suppose the text strings of colours on your Sheet1 is in a Table named Tbl_LookUp
Suppose the phrases on your Sheet2 is in another Table named Tbl_Phrases
Go to the Data tab of your Excel and load both tables to the Power Query Editor (you can google how to load data from a table to the PQ Editor in Excel 2016). Please note the screenshot is from Excel 365.
Once loaded, go to the Tbl_Phrases query, and action the following steps:
Add an indexed column starting from 1
Split the Phrases column by delimiter, use space as the delimiter and choose to put the outcome into rows
Merge the current query with the Tbl_LookUp query, use the Phrase column to match the Old Text column
Expand the new column to show contents from New Text column
Group the New Text column by the Index column, you can choose to sum the values in the New Text column, and it will come up as an error after the grouping. Go to the formula field and replace this part of the formula List.Sum([New Text]) with Text.Combine([New Text],", "). Hit enter and the error will be corrected to the desired text string.
The following is the full M Code for the above query. You can copy and paste it in the Advanced Editor without manually going through each step:
let
Source = Excel.CurrentWorkbook(){[Name="Tbl_Phrases"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Phrases", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Added Index", {{"Phrases", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Phrases"),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Phrases", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Phrases"}, Tbl_LookUp, {"Old Text"}, "Tbl_Replace", JoinKind.LeftOuter),
#"Expanded Tbl_Replace" = Table.ExpandTableColumn(#"Merged Queries", "Tbl_Replace", {"New Text"}, {"New Text"}),
#"Grouped Rows" = Table.Group(#"Expanded Tbl_Replace", {"Index"}, {{"Look up color", each Text.Combine([New Text],", "), type nullable text}})
in
#"Grouped Rows"
When you finish adding an index column in the Tbl_Phrases query, which is Step 1 from the above, you can make a copy of the query (simply right click the original query and select "duplicate"), then you will have a second query called Tbl_Phrases (2). No need to work on this query until you finish editing the original query ended up with desired text strings.
Then you can merge the Tbl_Phrases (2) query with the Tbl_Phrases query using the index column. Expand the new column to show the content from the look up colour column. Lastly, merge the Phrases column with the look up color column with delimiter (space)-(space), and remove the index column, then you should have the desired text string.
Here is the M Code for the Tbl_Phrases (2) query. Just a reminder, you must finish with the Tbl_Phrases query first otherwise the merging query step will lead to an error:
let
Source = Excel.CurrentWorkbook(){[Name="Tbl_Phrases"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Phrases", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Merged Queries" = Table.NestedJoin(#"Added Index", {"Index"}, Tbl_Phrases, {"Index"}, "Tbl_Phrases", JoinKind.LeftOuter),
#"Expanded Tbl_Phrases" = Table.ExpandTableColumn(#"Merged Queries", "Tbl_Phrases", {"Look up color"}, {"Look up color"}),
#"Merged Columns" = Table.CombineColumns(#"Expanded Tbl_Phrases",{"Phrases", "Look up color"},Combiner.CombineTextByDelimiter(" - ", QuoteStyle.None),"Merged"),
#"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"Index"})
in
#"Removed Columns"
You can then load the Tbl_Phrase (2) query to the desired worksheet within the same workbook (or to somewhere on Sheet2).
Let me know if you have any questions.
I would like to create some kind of LOOKUPVALUE on text in DAX that will match a sentence with a particular keyword. For instance in the example below the second and third row have a hit because “Apple” and "Chicken" is in the string. The problem is that the text is in a string and not a standalone value.
Table 1
Table 2
Output
EDIT, improved answer: this new version also works when there are multiple keys in one string.
I think PowerQuery is the natural place to perform an operation like this.
The Output table would look like this:
A description of the applied steps:
Source: a reference to Table1
Added Column Key lists: adds a custom column with lists of the Table2[Key] value(s) that are in the [String] value. This is the logic for this Custom column:
For each row the function selects the values from the Table2[Key] column that it finds in the [String] value. It then returns a list that holds only the selected values.
Expanded Key list: expands the lists in the [Key] column
Join with Table2 on Key: Joins with Table2 on the Key Value
Expanded Table2: Expands the table values in the [ItemTables] column and keeps the [Item] column
Group and concate keys/items: Groups the Output table on String, concatenating the Keys and the Items. If you don't want to see the [Key] column, delete {"Key", each Text.Combine([Key], " | "), type text}, from this step
The script in the Advanced Editor looks like this:
let
Source = #"Table1",
#"Added Column Key lists" = Table.AddColumn(Source, "Key", (r) => List.Select(Table.Column(Table2,"Key"),each Text.Contains(r[String],_,Comparer.OrdinalIgnoreCase)),type text),
#"Expanded Key lists" = Table.ExpandListColumn(#"Added Column Key lists", "Key"),
#"Join with Table2 on Key" = Table.NestedJoin(#"Expanded Key lists", {"Key"}, Table2, {"Key"}, "ItemTables", JoinKind.LeftOuter),
#"Expanded ItemTables" = Table.ExpandTableColumn(#"Join with Table2 on Key", "ItemTables", {"Item"}, {"Item"}),
#"Group and concate keys / items" = Table.Group(#"Expanded ItemTables", {"String"},{{"Key", each Text.Combine([Key], " | "), type text},{"Item", each Text.Combine([Item], " | "), type text}})
in
#"Group and concate keys / items"
Here is a link to my .pbix file
I created the following dummy data sets.
My interpretation of what your after is to Identify if a sentence contains a key word.
This can be done via a calculated column with the following formula -
Lookup = LOOKUPVALUE(Table2[Result],Table2[LookUp], IF(SEARCH("Apple",Table1[Sentence],,0)> 0, "Apple",""))
You can combine the If and Search Functions with the Lookupvalue function.
The formula is searching for the word "Apple" and then returning its position within the text and if no result is found, displays 0.
The IF statement then takes any result greater then 0, as anything greater then 0 means a result has been found and that is its position within the string, and states "Apple". This then becomes your lookup value.
This then displays as bellow
You can then replace the Blank ("") that is currently the result if false, with another if statement to look for another key word such as "Orange" and then add add that to your lookup table to pull through the result your after.
Hope this makes sense and helps!
Try this formula (see the picture which cell is where in my assumptions):
=IFERROR(INDEX($B$7:$B$9,MATCH(1,--NOT(ISERROR(FIND($A$7:$A$9,$A12))),0)),"-")