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
webportal
Impactful Individual
Impactful Individual

DAX: FIND or SEARCH part of a string in a column?

I want a custom column to search a part of a text within another column.

For example, I want to find out if "TRF" is in column Descrição do Movimento

 

Data Mov.   Data Valor  Descrição do Movimento  Valor em EUR
17-02-2017  17-02-2017  CONSTITUICAO 123/004    -2.000
17-02-2017  17-02-2017  TRF 0000082 CUSTOMER A  368
17-02-2017  17-02-2017  TRF 0000082 CUSTOMER B  66
17-02-2017  17-02-2017  TRF 0000082 CUSTOMER C  98
17-02-2017  17-02-2017  TRF 0000082 CUSTOMER D  861

This is the code I'm trying to the calculated column:

Column = FIND("TRF";'ContaBancoX'[Descrição do Movimento])

And also:

Column = SEARCH("TRF";'ContaBancoX'[Descrição do Movimento])

Both returning the error:

The search Text provided to function 'SEARCH' could not be found in the given text.

And all the rows return #ERROR

How to fix this? Thanks in advance!

PS: Here's a link for the table: https://docs.google.com/spreadsheets/d/1vc6c4rV7-NpE1ClbF0dYcWa0PhH4hIMr38QU4EFKuxc/edit?usp=sharing

1 ACCEPTED SOLUTION

They are optional.  The problem with the function is that if it can't find your text in the string it throws an error (unless you specify the 4th argument), and Power BI errors the whole column.

 

The first row in your posted dataset doesn't contain the text 'TRF' and that is what is causing the errors for all the other rows.  Seems a bit silly to me, but if you use the 4th argument then it doesn't effect the other rows.

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

14 REPLIES 14
EMP
Advocate II
Advocate II

You could also use CONTAINSSTRING. 

 

IF(CONTAINSSTRING('Table[Colum], "FindMe"), "Found It", "Didn't Find It")

Kinsey
Advocate II
Advocate II

I find a better solution is to use Switch True and Search with zero as the 4th part of search and fin trus for anything greater than zero (tehn use the ELSE side of switch for anything else) like so:

 

=SWITCH(TRUE(),
                SEARCH("House",YetiData[Centre],,0)>0,"Building"
                ,SEARCH("Car",YetiData[Centre],,0)>0,"Vehicle"
                ,"Other"
                    )

 

Phil_Seamark
Employee
Employee

Please try this 

 

Column = SEARCH("TRF";'ContaBancoX'[Descrição do Movimento],,0)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Its used for me... Thanks 

Yes, that works.

But aren't the 3rd and 4th argument optional?

They are optional.  The problem with the function is that if it can't find your text in the string it throws an error (unless you specify the 4th argument), and Power BI errors the whole column.

 

The first row in your posted dataset doesn't contain the text 'TRF' and that is what is causing the errors for all the other rows.  Seems a bit silly to me, but if you use the 4th argument then it doesn't effect the other rows.

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Can you please look into the problem in the link ? 
Question on StackOverflow

Can you please look into the problem in the link ? 
Question on StackOverflow

@webportal

You have another option to handle the error and also to return Text instead of a Number

 

TRF Check (DAX Number) =
SEARCH ( "TRF"; 'ContaBancoX'[Descrição do Movimento];; 0 )

TRF Check (DAX Text) =
IF (
    ISERROR ( SEARCH ( "TRF"; 'ContaBancoX'[Descrição do Movimento] ) );
    "No";
    "Yes"
)

Plus you can also very easily handle this in the Query Editor by creating a Conditional column using the User Interface

 

QE - Conditonal Column (DAX).gif

 

Hope this helps! Smiley Happy

webportal
Impactful Individual
Impactful Individual

Yep, that's great too!

Hello!

 

Can I use this formula and how do I apply it if I want to search "yes or no" and that I only show the values of "Descrição do Movimento" according to my search?

I do not know if I explain, but... if I have a filter: yes/no, and I want when I select "Yes"  only get the values that contain "yes" in a list.

 

Thanks for the support

Hi 

 

How would this work with nesting multiple ORs for the text searching?

webportal
Impactful Individual
Impactful Individual

This is cool, thanks a lot!

 

In fact, I need to categorize each row according to the text in column "Descrição do Movimento", so I guess I'll need nested IF statements or a SWITCH function.

SWITCH statements are waaay cooler than nested IF statements 🙂


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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.