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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to check that a specific text exists between two delimiters with M ?

Hello!

 

I'm looking to write a condition that checks that a text exists between two delimiters (without extraction). Exemple :

 

Data = aaa bbb ccc ddd eee rrr

 

How to check that "ccc" exists between "bbb" and "ddd"?

 

Thanks!

1 ACCEPTED SOLUTION

You could use Regular Expressions (and @ImkeF has a blog on using them), or you could split your string on the space, and check that the delimiters are present and in the correct order.

i.e:

Edited to account for missing delimiter as the first element

 

    #"Added Custom" = Table.AddColumn(#"Previous Step", "Matches", each 
        let 
          split = Text.Split([Column with the strings to be tested]," "),
          params = {"bbb"} & {"ccc"} & {"ddd"},
          pos = List.Accumulate(params,{},(x,y)=> x & {List.PositionOf(split,y)})
        in
    in  
          if List.Contains(pos,-1) then false else 
          pos{0} < pos{1} and pos{1} < pos{2}, type logical)

 

 

 

 

View solution in original post

4 REPLIES 4
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
would that work for you?:

Text.BetweenDelimiters("aaa bbb ccc ddd eee rrr", "bbb ", " ddd") = "ccc"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Thanks ! it works fine when there are no values between "ccc" and "bbb" or "ddd"

 

How do I do the same for this case :

 

Data = aaa bbb xxx ccc ttt ddd eee rrr

 

How to verify that "ccc" exists between "bbb" and "ddd"

You could use Regular Expressions (and @ImkeF has a blog on using them), or you could split your string on the space, and check that the delimiters are present and in the correct order.

i.e:

Edited to account for missing delimiter as the first element

 

    #"Added Custom" = Table.AddColumn(#"Previous Step", "Matches", each 
        let 
          split = Text.Split([Column with the strings to be tested]," "),
          params = {"bbb"} & {"ccc"} & {"ddd"},
          pos = List.Accumulate(params,{},(x,y)=> x & {List.PositionOf(split,y)})
        in
    in  
          if List.Contains(pos,-1) then false else 
          pos{0} < pos{1} and pos{1} < pos{2}, type logical)

 

 

 

 

Anonymous
Not applicable

Thanks a lot !

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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 Kudoed Authors