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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
mcash
Helper I
Helper I

Text to Column Between Delimiters but maintain text without delimiters

How can I extract the text between comma delimiters while still keeping text with no delimiters? Below is an example of what I am starting with (Before) and the text I want to keep (After).

 

BeforeAfter
Service ChargeService Charge
Service ChargeService Charge
TX, Product 001, 220WProduct 001
LA, Product 001, 220WProduct 001
OK, Product 001, 220WProduct 001

 

1 ACCEPTED SOLUTION

@mcash Including sample data that represented all of your edge cases would have saved a lot of back and forth and time wasted.

After After = 
    IF(
        NOT(CONTAINSSTRING([Before],",")),
        [Before],
                VAR __Before = SUBSTITUTE([Before],", ",",")
                VAR __First = FIND(",",__Before)
                VAR __Second = FIND(",",__Before,__First+1, -1)
                VAR __Result = 
                    IF(
                        __Second > 0,
                        MID(__Before,__First + 1, __Second - __First - 1),
                        MID(__Before,__First + 1, LEN([Before]) - __First - 1)
                    )
            RETURN
                __Result
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
Greg_Deckler
Community Champion
Community Champion

@mcash Try:

After Column = 
    IF(
        NOT(CONTAINSSTRING([Before],",")),
        [Before],
                VAR __First = FIND(",",[Before])
                VAR __Second = FIND(",",[Before],__First+2)
                VAR __Result = MID([Before],__First + 2, __Second - __First - 2)
            RETURN
                __Result
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler I am receiving an error.

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

@mcash You must have some rows with just a single comma, try:

 

After Column = 
    IF(
        NOT(CONTAINSSTRING([Before],",")),
        [Before],
                VAR __First = FIND(",",[Before])
                VAR __Second = FIND(",",[Before],__First+2, -1)
                VAR __Result = 
                    IF(
                        __Second > 0,
                        MID([Before],__First + 2, __Second - __First - 2),
                        MID([Before],__First + 2, LEN([Before]) - __First - 1)
                    )
            RETURN
                __Result
    )

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

This works well, but in my giant list of products there are some that do not have a space after the first comma; i.e. TX,Product 001 so it returns it as "roduct 001". Getting closer haha!

@mcash Including sample data that represented all of your edge cases would have saved a lot of back and forth and time wasted.

After After = 
    IF(
        NOT(CONTAINSSTRING([Before],",")),
        [Before],
                VAR __Before = SUBSTITUTE([Before],", ",",")
                VAR __First = FIND(",",__Before)
                VAR __Second = FIND(",",__Before,__First+1, -1)
                VAR __Result = 
                    IF(
                        __Second > 0,
                        MID(__Before,__First + 1, __Second - __First - 1),
                        MID(__Before,__First + 1, LEN([Before]) - __First - 1)
                    )
            RETURN
                __Result
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

This works, thank you. I understand there is a lot of back and forth, but my data set is hundreds of thousands of rows long and I cannot necessarily capture every scenario and did not know that a space or no space mattered; I'm very novice.

 

Thank you again for your help.

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