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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
AnasBach
Regular Visitor

"IF Contains Text" function on a table querying a LIST

Hi,

 

This is my first post in here, hope you guys can help me with my request.

 

I have a table with customers feedback and I need to classify those feedback in categories (Advisor's Behavior, Products, Stores ...). Those categories contain key words. I formatted the categories as differents lists, therefore I have a list for each category and a table with feedbacks.

 

What I'm trying to do is that whenever there's one of the keywords on the list that get flagged on the table, it returns the value 1, if not 0. I don't need to know which key word is mentionned exactly, I just need to know if that category is mentionned or not.

 

I have it up and running on Excel with logic functions, but I need to do it in PowerBI with M Functions. I tried the "Contain" function with a custom column but I can't reference an external list on it.

 

I'm trying to get something like this : IF text_column, CONTAINS one of the words in the CATEGORY LISTS, then 1 if not 0

 

Let me know if you guys might need more details or perhaps the pbix file.

 

Thank you,

Anas

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

@AnasBach,

 

You may use SEARCH Function to add a calculated column in DAX.

Column =
SIGN (
    SUMX ( Table2, SIGN ( SEARCH ( Table2[category], Table1[feedback],, 0 ) ) )
)
Community Support Team _ Sam Zha
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

6 REPLIES 6
v-chuncz-msft
Community Support
Community Support

@AnasBach,

 

You may use SEARCH Function to add a calculated column in DAX.

Column =
SIGN (
    SUMX ( Table2, SIGN ( SEARCH ( Table2[category], Table1[feedback],, 0 ) ) )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-chuncz-msftthank you so much for your reply!

 

It did work perfectly as a a new column on DAX but I can't have it inserted as a custom column on the query editor?

 

I will need to do some transformation later-on on the Data gathered from that measure on the query editor.

@AnasBach,

 

You may combine the two queries in The Advanced Editor or invoke a custom function.

https://msdn.microsoft.com/en-us/library/mt185361.aspx

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

@v-chuncz-msft  thank you for your reply.

 

Forgive my ignorance, but I just can't figure out how to get from creating this DAX function to a Custom Function on the Advanced Editor ..

 

 

Unfriendliness = SIGN (
SUMX(Unfriendliness; SIGN(SEARCH(Unfriendliness[Unfriendliness];Verbatims[Comment];;0)))

 

 

What I'm trying to do is to get a table with all verbatim cateogries labeled as 1 or 0 and then I'm going to unpivot all the categories. In steps it should be something like that :

 

1st Step : Invoke Custom Function to search for key words on the text and display 1 if True, 0 if False

VerbatimKindnessResponse TimeClarity
It takes too much time to get someone on the phone010
You customer service is great, very nice person on the phone100
All the information given was very clear, thank you00

1

 

Final Result : Transform Data - Unpivot Categories Attributes

 

VerbatimCategory
It takes too much time to get someone on the phoneResponse Time
You customer service is great, very nice person on the phoneKindness
All the information given was very clear, thank youClarity

 

My apologize for the long reply, thank you in advance for your help and patience 😄

Hi @AnasBach,

 

Once you have unpivoted the dataset, push it to the Data Model (by clicking on Close and Apply).  Then write the calculated column formula suggested above.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

My apologies @Ashish_Mathur for my tardy reply.

 

The calculated formula comes before the unpivot actually, yet It still doesn't get what need exactly .. The custom measure is only available on DAX. I need it as a Custom Function that can be invoked on other entries on the Query Editor. Then, I can unpivot the attributes and get a nicely classified table.

 

Thank you

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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