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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
finno14
Helper I
Helper I

How do I find exact text within a string?

Hello,

 

As always, I apologise if this is common knowledge within Power Bi.

 

How do I go about finding & counting exact text, within a string-- For Example, I want to find comments that contain the isolated phrase "TU". However, the formula I am currently using counts comments that contains a word with TU within it ("Turntable", "Tubby"). 

 

The Current formula I am using is:

VAR XXXX =
 
var TU = CALCULATE(COUNTROWS(FILTER(
                                                                       'ssc_db_001 ga_report',SEARCH("TU",'ssc_db_001 ga_report'[Comment],,0)>0)))

Return TU
 

I am aware of how to do it within Excel, but I am struggling to bring it into Power BI.

 

Any help, would be greatly appreciated!



 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@finno14 , Try CONTAINSSTRINGEXACT 

 

CONTAINSSTRINGEXACT('ssc_db_001 ga_report'[Comment], "TU")

 

https://docs.microsoft.com/en-us/dax/containsstringexact-function-dax

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@finno14 , Try CONTAINSSTRINGEXACT 

 

CONTAINSSTRINGEXACT('ssc_db_001 ga_report'[Comment], "TU")

 

https://docs.microsoft.com/en-us/dax/containsstringexact-function-dax

@amitchandak Thank you for this... However if I could be cheeky and add another layer, often I will be looking for multiple keywords within a large data set, grouped together ie count incidents with "TU" & "BU" within the comments . however, if both key words are within the same text, I believe it counts 2 instead of 1? Is it possible to amend this?

 

Thank you again for your help.

Hi @finno14 ,

 

Try this

Column = CONTAINSSTRINGEXACT([Column1],"TU")|| CONTAINSSTRINGEXACT([Column1],"BU")

CONTAINSSTRINGEXACT returns True/False. How do you want to count?

9.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-stephen-msft,

 

Sorry for my delayed response, I have not had access to the site.

 

Ideally I would like to count each incident where "TU" or "BU" appears in a comment/ text string, but only count once if one of them appears within a sentence. The Original formula and the one accepted as a solution- Counts 2 if TU & BU appear in the same text string as opposed to 1.

 

I hope I have coveyed my message well!

 

Kind regards,


Alex

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.