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

Search text string within column

I'm trying to find the position (in nr. of characters) of the word "span" in column "order_product_name" of table "order_product".

For that, I'm using a calculated column with the formula:

Coluna 2 = SEARCH("span";'order_product'[order_product_name])

This syntax is exactly the same as used in the DAX reference so I have no idea why it is returning an error.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Interesting...

I've found this in the DAX reference for SEARCH:

 

"If the find_text cannot be found in within_text, the formula returns an error. This behavior is like Excel, which returns #VALUE if the substring is not found. Nulls in within_text will be interpreted as an empty string in this context."

 

So your "IFERROR" takes care of these cases where the "span" is not found.

I think it's the way to do it.

 

View solution in original post

4 REPLIES 4
Ramadevi
Frequent Visitor

Hi,

 

Can you try below. 

 

Created New column with below logic.

 

SearchColumn = SEARCH("Re",<Column Name>,1,0)

 

It gave me the position of the word 'Re' 

 

For example,

 

Column1     SearchColumnResult

----------      ----------------------

 

I am Ready     6

 

If the text is not found, i will get 0. Because i mentioned 0 as NotFoundValue parameter

 

Anonymous
Not applicable

Maybe a semicolon is the issue....

Try comma instead:

Coluna 2 = SEARCH("span",'order_product'[order_product_name])

 

webportal
Impactful Individual
Impactful Individual

Thanks, but no.

We use semicolons here to separate argument formulas.

 

I found that if I use:

Coluna 2 = IFERROR(SEARCH("span",'order_product'[order_product_name]); BLANK())

It works, although it doesn't make a lot of sense to me.

Anonymous
Not applicable

Interesting...

I've found this in the DAX reference for SEARCH:

 

"If the find_text cannot be found in within_text, the formula returns an error. This behavior is like Excel, which returns #VALUE if the substring is not found. Nulls in within_text will be interpreted as an empty string in this context."

 

So your "IFERROR" takes care of these cases where the "span" is not found.

I think it's the way to do it.

 

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.