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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
PowerBINewbie7
New Member

Extracting substrings: FIND throwing error despite being skipped by IF Statement

Hi all!

 

I'm trying to extract a column containing information (in this example: the numbers) from a column which looks something like this:

 

INFORMATION01
INFORMATION02
ABCDEFG Info: 03 HIJKLMNOPQR
I felt like putting something else here. Info: 04 And some more text!
This row contains a typo. Ifo: 05 Lorem ipsum dolor

 

My general idea is to create a DAX statement along the lines of:

 

"IF(CONTAINSSTRING(Table[column], "INFORMATION"), RIGHT(Table[column], 2),
IF(CONTAINSSTRING(Table[column], "Info: "), MID(Table[column], FIND("Info: ", Table[column])+7, 2), "Info not found")

 

Unfortunately, this causes the FIND function to throw an error for the whole column because not all rows contain "Info" and therefore, it could not return anything in those rows even if it wouldn't have to because CONTAINSSTRING would return false. Is there some way around this? (Eventually, I'd like to also account for typos with another IF-Statement)

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PowerBINewbie7 ,

You can update the formula of calculated column as below:

Column = 
VAR _information =
    SEARCH ( "INFORMATION", 'Table'[Text], 1, 0 )
VAR _info =
    SEARCH ( "Info: ", 'Table'[Text], 1, 0 )
VAR _info1 =
    SEARCH ( "Ifo: ", 'Table'[Text], 1, 0 )
RETURN
    SWITCH (
        TRUE (),
        _information > 0, RIGHT ( 'Table'[Text], 2 ),
        _info > 0, MID ( 'Table'[Text], VALUE ( _info ) + 6, 2 ),
        _info1 > 1, MID ( 'Table'[Text], VALUE ( _info1 ) + 5, 2 ),
        "Info not found"
    )

vyiruanmsft_0-1708932953198.pngBest Regards

View solution in original post

8 REPLIES 8
timalbers
Super User
Super User

Ok this is strange.. I just simply copied your DAX logic and I am not able to reproduce the error.

 

timalbers_0-1708696444857.png


—————————————————————————————
✔️ If my answer helped you, please consider marking it as a solution.

Yup, my bad! I did not try my example code on this example, because I assumed the error would occur as it does in the table I'm actually working on... Sorry for wasting your time! I'll go back to figuring out what makes the table I'm working on different from my example.

Not a problem at all

If there are still issues, just come back to this thread. 
I will try to help you best as I can


—————————————————————————————
✔️ If my answer helped you, please consider marking it as a solution.

Thanks a lot!

As an update: For some reason, using SEARCH instead of FIND fixed it. I played around with my original table and "FIND"ing some strings worked fine, but not the ones I needed. The only explanation I can think of is that maybe FIND reacts to special characters (specifically: dots) in some way I was unaware of and SEARCH doesn't.

Anonymous
Not applicable

Hi @PowerBINewbie7 ,

You can update the formula of calculated column as below:

Column = 
VAR _information =
    SEARCH ( "INFORMATION", 'Table'[Text], 1, 0 )
VAR _info =
    SEARCH ( "Info: ", 'Table'[Text], 1, 0 )
VAR _info1 =
    SEARCH ( "Ifo: ", 'Table'[Text], 1, 0 )
RETURN
    SWITCH (
        TRUE (),
        _information > 0, RIGHT ( 'Table'[Text], 2 ),
        _info > 0, MID ( 'Table'[Text], VALUE ( _info ) + 6, 2 ),
        _info1 > 1, MID ( 'Table'[Text], VALUE ( _info1 ) + 5, 2 ),
        "Info not found"
    )

vyiruanmsft_0-1708932953198.pngBest Regards

Glad, you found a way!
Only difference I know: FIND is case sensitive, SEARCH is not.
However, have a nice weekend!


—————————————————————————————
✔️ If my answer helped you, please consider marking it as a solution.
timalbers
Super User
Super User

Hi @PowerBINewbie7,
could you please share a screenshot of the error message? I cannot reproduce the error.

One thing to mention besides that: If your tabele name really is "Table", you'll have to put it like this: 'Table'[column], because "Table" is a reserved word. Table[column] would return an error.


—————————————————————————————
✔️ If my answer helped you, please consider marking it as a solution.

Hi @timalbers,

The error message is just this: 

PowerBINewbie7_1-1708695724547.png

with the column displaying "#ERROR" in each row.

My table is not actually named table, so that can't be the problem.

I've also tried replacing the MID-FIND part with just "Info found" and that works perfectly. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors