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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

DAX: Need help to find the 2nd, 3rd delimited values based on string

Assume we have the following column called [ERPCode] below. I want to dynamically return the second or third value within my serial key. If my ERP code contains "MI" return the second value, but if my ERP code contains "SI" then return me the third value in my serial key. A sample output is provided for reference.

mohancsg_0-1683710653156.png

 

Please help.

Thanks,

Mohan V.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

You just modify the dax formula provided by @Fowmy .

Please try below dax formula:

Column =
VAR _code = [ERPCode]
VAR _len =
    LEN ( _code )
VAR _a =
    FIND ( ".", _code )
VAR _b =
    IFERROR ( FIND ( ".", _code, _a + 1 ), 0 )
VAR _c =
    IFERROR ( FIND ( ".", _code, _b + 1 ), 0 )
VAR _val =
    SWITCH (
        TRUE (),
        CONTAINSSTRING ( _code, "MI" ),
            IF ( _b <> 0, MID ( _code, _a + 1, _b - _a - 1 ), MID ( _code, _a + 1, _len ) ),
        CONTAINSSTRING ( _code, "SI" ),
            IF ( _c <> 0, MID ( _code, _b + 1, _c - _b - 1 ), MID ( _code, _b + 1, _len ) )
    )
RETURN
    _val

vbinbinyumsft_0-1685519973322.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

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

You just modify the dax formula provided by @Fowmy .

Please try below dax formula:

Column =
VAR _code = [ERPCode]
VAR _len =
    LEN ( _code )
VAR _a =
    FIND ( ".", _code )
VAR _b =
    IFERROR ( FIND ( ".", _code, _a + 1 ), 0 )
VAR _c =
    IFERROR ( FIND ( ".", _code, _b + 1 ), 0 )
VAR _val =
    SWITCH (
        TRUE (),
        CONTAINSSTRING ( _code, "MI" ),
            IF ( _b <> 0, MID ( _code, _a + 1, _b - _a - 1 ), MID ( _code, _a + 1, _len ) ),
        CONTAINSSTRING ( _code, "SI" ),
            IF ( _c <> 0, MID ( _code, _b + 1, _c - _b - 1 ), MID ( _code, _b + 1, _len ) )
    )
RETURN
    _val

vbinbinyumsft_0-1685519973322.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.

Fowmy
Super User
Super User

@Anonymous 

Will a Power Query solution work for you?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy No, I am looking for dax solution.

@Anonymous 

Here is the DAX solution, add this as a Calculated Column:

Key = 
IFERROR(
    VAR __EPR = [ERP Code]
    VAR P = LEFT( __EPR , 2 )
    VAR P1 =  FIND("." , __EPR) 
    VAR P2 =  FIND("." , __EPR , P1 + 1 )
    VAR P3 =  FIND("." , __EPR , P2 + 1 )
    VAR RESULT = 
        SWITCH(
            P,
            "MI", MID( __EPR, P1 + 1 , P2 - P1 - 1 ),
            "SI", MID( __EPR, P2 + 1 , P3 - P2 - 1 )
        )       
    RETURN
        RESULT,
    BLANK()
)
   

Fowmy_0-1683715723596.png

 





Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy It is working but only issue here is if i dont have any delimeter then it is returing blank as in below case.

mohancsg_0-1683717586968.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors