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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sja133
Frequent Visitor

Extract 7 digit number after specific letter in Power Query

Hi

 

Trying to extract a 7 digit order number from a text string. Order numbers start with O followed by 7 digits. Problem is order number can appear anywhere in the string. Example in table below, have highlighted what we need to extract. 

 

Any guidance would be appreciated 🙂

 

RUSH REQUEST: O4977663 Customer 123412 QDE Reference BOOTSTOCK
PFD TEMPLATE : O4977441 Customer 156084 QDA Reference PT987443 
RUSH REQUEST: O4977743 Customer 121411 QDA Reference 91956
RUSH REQUEST: O4977807 Customer 147611 QDA Reference JESSE.SMITH 
URGENT REQUEST FOR DELIVERY PLEASE - O4976974 A/c 127087 
RUSH REQUEST: O4977824 Customer 337216 VDA Reference 4501403367 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @sja133 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc9BU8IwEIbhv7LTs2LSbLOJt0oXQYspScoM0+HEhBswg/r/rahjEbnv98y7XZf5NkzB86LlEO/BoSXSWsH4/fXtsEtHkLlCmcOiYvBpm45pv0nw4FwM0Y2fs/VNlzWTCiLPm7qMDN8GohwYhRYGe6McGE20pj9TcDL+ySA8y5Ao5R/CSlvoa3MjaDBH0hfzJw6BR2E+i9OviNY/8kv8cWDiPFRcz5bsV9DUXAaG2xOuLSGUd5s+i4Shqy+YHH8blKJcalieNWAhJAql9Cey/gA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Result", each List.Select(Text.Split([Column1],  " "), 
each Text.Start(_,1) = "O" and Text.Length(_)=8  and Text.Length(Text.Select(Text.End(_,7), {"0".."9"})) = 7)),
    
   #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Result", each Text.Combine(List.Transform(_, Text.From)), type text})
in
    #"Extracted Values"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @sja133 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc9BU8IwEIbhv7LTs2LSbLOJt0oXQYspScoM0+HEhBswg/r/rahjEbnv98y7XZf5NkzB86LlEO/BoSXSWsH4/fXtsEtHkLlCmcOiYvBpm45pv0nw4FwM0Y2fs/VNlzWTCiLPm7qMDN8GohwYhRYGe6McGE20pj9TcDL+ySA8y5Ao5R/CSlvoa3MjaDBH0hfzJw6BR2E+i9OviNY/8kv8cWDiPFRcz5bsV9DUXAaG2xOuLSGUd5s+i4Shqy+YHH8blKJcalieNWAhJAql9Cey/gA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Result", each List.Select(Text.Split([Column1],  " "), 
each Text.Start(_,1) = "O" and Text.Length(_)=8  and Text.Length(Text.Select(Text.End(_,7), {"0".."9"})) = 7)),
    
   #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Result", each Text.Combine(List.Transform(_, Text.From)), type text})
in
    #"Extracted Values"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

sja133
Frequent Visitor

Thank you @AlB that worked awesomely. i can study the query now and learn something new 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.