Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Indexing keywords found in emails

I have a table that contains plain text from emails that I need to search for a specific list of keywords and then return a list of the emails that contain those words and then do reporting on them. There are about 500k emails and 30 odd words to look for. I can search for and count the emails containing the words with a calculated column, but this does not allow me to filter the list of emails by the words. My current tables look like this:

Word

WordCount
email0
phone2
mfa1
clock1
text4

Email

EmailIDEmailText
1Various text
2Text about phones
3Text about clocks
4Text about mfa
5My phone is broken 😞

 

Doing the count takes FOREVER and I'm not able to filter the emails by the words in a visual afterwards. I though that an index table like this would do the job and make it a bit quicker:

 

WordEmailID
phone2
phone5
clock3
mfa3
text1
text2
text3
text4

 

But I can't figure out how to create this from the existing tables. Is anyone able to help, either with creating this table or a smarter suggestion on how I can do this? Thanks for any help.

1 ACCEPTED SOLUTION
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

You can use the M query, kindly find my below results:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpLLMrMLy1WKEmtKFGK1YlWMgIKhgA5ColJ+aUlCgUZ+XmpxWAZY1SZ5Jz85GyIjAmqTG5aIljYFCjsWwkxQiGzWCGpKD87NU8pNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EmailID = _t, EmailText = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"EmailID", Int64.Type}, {"EmailText", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Word[Word]),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Inserted Lowercased Text" = Table.AddColumn(#"Expanded Custom", "lowercase", each Text.Lower([EmailText]), type text),
    #"Added Conditional Column" = Table.AddColumn(#"Inserted Lowercased Text", "Custom.1", each if Text.Contains([lowercase], [Custom]) then [EmailID] else null)
in
    #"Added Conditional Column"

 

5.PNG

Pbix attached.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

View solution in original post

3 REPLIES 3
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

You can use the M query, kindly find my below results:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpLLMrMLy1WKEmtKFGK1YlWMgIKhgA5ColJ+aUlCgUZ+XmpxWAZY1SZ5Jz85GyIjAmqTG5aIljYFCjsWwkxQiGzWCGpKD87NU8pNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EmailID = _t, EmailText = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"EmailID", Int64.Type}, {"EmailText", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Word[Word]),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Inserted Lowercased Text" = Table.AddColumn(#"Expanded Custom", "lowercase", each Text.Lower([EmailText]), type text),
    #"Added Conditional Column" = Table.AddColumn(#"Inserted Lowercased Text", "Custom.1", each if Text.Contains([lowercase], [Custom]) then [EmailID] else null)
in
    #"Added Conditional Column"

 

5.PNG

Pbix attached.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Anonymous
Not applicable

Thank you, this was a big help. However, anyone else who is trying this should be careful to remove blanks and nulls from their equivalent of EmailID column or you will get errors.

harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Please see if the solution helps.

 

https://community.powerbi.com/t5/Desktop/Keyword-search-of-multiple-columns-with-multiple-keywords/m-p/1025528

 

Regards,

HarshRegards,
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.