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
Marcus_E
Helper I
Helper I

Query column CONTAIN

Hi

 

I'm fairly new to Power BI and am hoping some more experienced users could help point me in the right direction.

 

I have a data set of transactions from a procurement system that includes a column originating from a 'free-form' entry field into which users can manually enter a purchase order number. Not all records have a purchase order number and the data can include both numeric purchase order details as well as random text information.

 

I'm trying to modify my query to extract from any records that contain a purchase order number, the actual purchase order number and return it to a new column in the query. If I was using Excel I would use a CONTAIN filter but as I don't want to filter I need some way to extract the 11 digit number and return it to a separate column which retaining all other records that don't have a purchase order number in this column.

 

For example the numbering sequence for all purchase orders begins with either '4500' or '4700' and are 10 characters long, so I'd like to a) recognise each record that contains '4500' or '4700' and extract the first 10 characters. Any records that don't match this criteria would simply remain blank.

 

An example of the data set and desired outcome is tabled below.

Existing data fieldDesired result
No purchase order0 or "Blank"
No purchase order0 or "Blank"
No purchase order0 or "Blank"
No purchase order0 or "Blank"
45000123456 Vendor purchase order details45000123456
45000123457 Vendor purchase order details45000123457
45000123458 Vendor purchase order details45000123458
45000123459 Vendor purchase order details45000123459
47000112233 Vendor purchase order details47000112233
47000112234 Vendor purchase order details47000112234
47000112235 Vendor purchase order details47000112235

 

 

Many thanks.

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

So in your query under "Add Column" you could click the "Add Custom Column" button and then paste in logic like the following:

 

if Text.StartsWith([Existing data field],"4500") 
or Text.StartsWith([Existing data field],"4700") 
then Text.Start([Existing data field],10) 
else null

View solution in original post

2 REPLIES 2
d_gosbell
Super User
Super User

So in your query under "Add Column" you could click the "Add Custom Column" button and then paste in logic like the following:

 

if Text.StartsWith([Existing data field],"4500") 
or Text.StartsWith([Existing data field],"4700") 
then Text.Start([Existing data field],10) 
else null

@d_gosbell  works perfectly, thanks for your response.

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.