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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
james_8287B
Regular Visitor

Creating a new table from text search

I have a Keywords table:

 

Keyword
KeywordOne
KeywordTwo
KeywordThree

 

and a Messages table:

 

IdMessage
1This message contains KeywordOne
2This contains KeywordOne and KeywordTwo
3KeywordTwo and KeywordThree are in this message
4No keywords here

 

I know how to search messages for keywords and expose this though a column, such as:

 

ContainsKeyword = IF(
      SUMX(Keywords,
           FIND(
                UPPER(Keywords[Keyword]),
                UPPER(Messages[Message])
                ,,0
               )
          ) > 0,
      TRUE,
      FALSE
     )

but what I'm looking to create a new table like so:

 

MessageIdKeyword
1KeywordOne
2KeywordOne
2KeywordTwo
3KeywordTwo
3KeywordThree

 

Some things to note:

 

  • Messages are of varying length
  • Some messages contain no keywords
  • Some messages contain many keywords
  • More keywords will be added over time, ideally with no additional changes other than adding the keyword to the table

If it's possible to do this with a measure on either table, that would be even better. Any help would be most appreciated.

 

Thanks

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@james_8287B

You would really have to create a new table (rather than adding a measure to either table) because your new table expresses a many-to-many relationship between Messages and Keywords.

 

You can create such a table using DAX, using GENERATE to join the tables:

MessageKeyword = 
VAR JoinedTables =
    GENERATE (
        Messages,
        FILTER (
            Keywords,
            FIND ( UPPER ( Keywords[Keyword] ), UPPER ( Messages[Message] ),, 0 ) > 0
        )
    )
RETURN
    SELECTCOLUMNS (
        JoinedTables,
        "MessageId", Messages[Id],
        "Keyword", Keywords[Keyword]
    )

I'm sure you could also do this with Power Query.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

@james_8287B

You would really have to create a new table (rather than adding a measure to either table) because your new table expresses a many-to-many relationship between Messages and Keywords.

 

You can create such a table using DAX, using GENERATE to join the tables:

MessageKeyword = 
VAR JoinedTables =
    GENERATE (
        Messages,
        FILTER (
            Keywords,
            FIND ( UPPER ( Keywords[Keyword] ), UPPER ( Messages[Message] ),, 0 ) > 0
        )
    )
RETURN
    SELECTCOLUMNS (
        JoinedTables,
        "MessageId", Messages[Id],
        "Keyword", Keywords[Keyword]
    )

I'm sure you could also do this with Power Query.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Super, thanks Owen!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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