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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
a_m_wood
Regular Visitor

Problem with extracting multiple substrings from a text field

Hi,

I'm trying to extract any occurences of text starting with the patter "-W" in a field "Name"

a_m_wood_1-1723011359948.png

 

I'm getting an error on record 2

Expression.Error: The 'count' argument is out of range.
Details:
6

If matches on this record is 

a_m_wood_2-1723011502995.png and the length of "Name" is 24,is my 'try' 'otherwise' not working or wrong?

 

Thanks in advance.

 

1 ACCEPTED SOLUTION
dufoq3
Community Champion
Community Champion

Hi @a_m_wood, check this

 

Result

dufoq3_0-1723014165578.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCknNLchJVQguUQhOTVcwNFDQVQg3NDExA9JBIW6G5uYmCpWpJQol+QpJqQoFRZnJqSlKsTrRSk6picn5eQpBKcj6zC0twJIhqcUlCrrhhkbGJgqJSckpIElTM3MLhdS09Ayl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
    Ad_ExtractedW = Table.AddColumn(Source, "Extracted W", each
        [ a = List.Combine(List.Transform({"- W", "-W"}, (x)=> Text.PositionOf([Name], x, Occurrence.All))),
          b = List.Transform(a, (x)=> Text.BeforeDelimiter(Text.Trim(Text.Range([Name], x), {" ", "-"}), " "))
        ][b], type list)
in
    Ad_ExtractedW

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

3 REPLIES 3
dufoq3
Community Champion
Community Champion

Hi @a_m_wood, check this

 

Result

dufoq3_0-1723014165578.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCknNLchJVQguUQhOTVcwNFDQVQg3NDExA9JBIW6G5uYmCpWpJQol+QpJqQoFRZnJqSlKsTrRSk6picn5eQpBKcj6zC0twJIhqcUlCrrhhkbGJgqJSckpIElTM3MLhdS09Ayl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
    Ad_ExtractedW = Table.AddColumn(Source, "Extracted W", each
        [ a = List.Combine(List.Transform({"- W", "-W"}, (x)=> Text.PositionOf([Name], x, Occurrence.All))),
          b = List.Transform(a, (x)=> Text.BeforeDelimiter(Text.Trim(Text.Range([Name], x), {" ", "-"}), " "))
        ][b], type list)
in
    Ad_ExtractedW

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Thank you!

dufoq3
Community Champion
Community Champion

You're welcome 😉


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors