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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Rimo72
New Member

Issues with string manipulation script

Hi,

 

I don't understand what i'm doing wrong. I'm appling this code to a new column called TW

 

TW =
IF(ISBLANK('Tickets'[TimeWorked]), BLANK(),
    IF (SEARCH("(", 'Tickets'[TimeWorked],1,BLANK()),
        MID('Tickets'[TimeWorked], SEARCH("(", 'Tickets'[TimeWorked], 1, BLANK()) + 1, SEARCH("min", 'Tickets'[TimeWorked], 1, BLANK()) - SEARCH("(", 'Tickets'[TimeWorked], 1, BLANK()) - 2),
        LEFT('Tickets'[TimeWorked], SEARCH("min",'Tickets'[TimeWorked],1,BLANK()) - 2)
    )
)
 
in the field 'Tickets'[TimeWorked] have 2 value format "15 minutes" or "2.08 hours (125 minutes)"
 
The error message is "LEFT has the wrong data type or has invalid value" regardless what I tryed, changing with static value in the LEFT statement, nothing works.
 
I'm trying to get the minutes value of each field.
 
Would it be possible to get some help with this.
 
Thanks,
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Rimo72 ,

The issue is likely with your SEARCH function. When SEARCH can't find the value (e.g. if the row value is blank) this kind of error can appear within LEFT. 

You just need adjust your dax formula, please try below dax formula:

 

TW =
IF (
    ISBLANK ( 'Table'[Time Worked] ),
    BLANK (),
    IF (
        SEARCH ( "(", 'Table'[Time Worked], 1, BLANK () ),
        MID (
            'Table'[Time Worked],
            SEARCH ( "(", 'Table'[Time Worked], 1, BLANK () ) + 1,
            SEARCH ( "min", 'Table'[Time Worked], 1, BLANK () )
                - SEARCH ( "(", 'Table'[Time Worked], 1, BLANK () ) - 2
        ),
        IF (
            ISBLANK ( SEARCH ( "min", 'Table'[Time Worked], 1, BLANK () ) ),
            BLANK (),
            LEFT (
                'Table'[Time Worked],
                SEARCH ( "min", 'Table'[Time Worked], 1, BLANK () ) - 2
            )
        )
    )
)

 

vbinbinyumsft_0-1684823225295.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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

4 REPLIES 4
Anonymous
Not applicable

Hi @Rimo72 ,

The issue is likely with your SEARCH function. When SEARCH can't find the value (e.g. if the row value is blank) this kind of error can appear within LEFT. 

You just need adjust your dax formula, please try below dax formula:

 

TW =
IF (
    ISBLANK ( 'Table'[Time Worked] ),
    BLANK (),
    IF (
        SEARCH ( "(", 'Table'[Time Worked], 1, BLANK () ),
        MID (
            'Table'[Time Worked],
            SEARCH ( "(", 'Table'[Time Worked], 1, BLANK () ) + 1,
            SEARCH ( "min", 'Table'[Time Worked], 1, BLANK () )
                - SEARCH ( "(", 'Table'[Time Worked], 1, BLANK () ) - 2
        ),
        IF (
            ISBLANK ( SEARCH ( "min", 'Table'[Time Worked], 1, BLANK () ) ),
            BLANK (),
            LEFT (
                'Table'[Time Worked],
                SEARCH ( "min", 'Table'[Time Worked], 1, BLANK () ) - 2
            )
        )
    )
)

 

vbinbinyumsft_0-1684823225295.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks it works. 

lbendlin
Super User
Super User

You are using 'Tickets'[TimeWorked] a lot.  Might want to put it in a variable.

 

Is this a measure or a column?

I do :). Will follow you recomandation. 🙂

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.