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

Extract a reference from a column based on specific criteria

Hi there,

 

I need to extract a specific reference from a column:

 

ReferenceResult
X201227638null
ZRET19/0014457ZRET19/0014457
ZRET23/0003605 ( X201212911-1-Madone 838954920)ZRET23/0003605
SB_X201463782  ZRET23/0010338ZRET23/0010338
X201436502-1 ZRET22/0004334 - TA-N100728285ZRET22/0004334
Leergut Z201294363-1-Fuerstenfeldbrucknull
( X201212911-1-Madone 838954920 ZRET14/55597 )ZRET14/55597

 

The string always starts with ZRET (sometimes Zret or zret).

 

Can someone please help?

 

Thanks,

Nigel

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

@Nigel_Mayhew1 

 

OK try this, works for me

 

= try List.Select(Text.Split(Text.Range([Reference], Text.PositionOf(Text.Upper([Reference]), "ZRET")), " "), each Text.Contains(_ , "ZRET")){0} otherwise null

 

PhilipTreacy_0-1730244251310.png

 

NOTE that in the 2nd lot of data you provided the 3rd line that begins Durchg mit gives a null becuase the code has a typo - it's ZRTE instead of ZRET.  I corrected this in my new example.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

6 REPLIES 6
PhilipTreacy
Super User
Super User

@Nigel_Mayhew1 

 

OK try this, works for me

 

= try List.Select(Text.Split(Text.Range([Reference], Text.PositionOf(Text.Upper([Reference]), "ZRET")), " "), each Text.Contains(_ , "ZRET")){0} otherwise null

 

PhilipTreacy_0-1730244251310.png

 

NOTE that in the 2nd lot of data you provided the 3rd line that begins Durchg mit gives a null becuase the code has a typo - it's ZRTE instead of ZRET.  I corrected this in my new example.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Phil,

 

That's absolutely perfect. Thank you!

 

Would you be kind enough please to just tell me what exactly I must change in the code if in the future I needed to look for strings other than ones starting with 'ZRET'?

 

For example if the strings were to begin with X5, L8 and Z1 and are 10 characters long.

 

Very much appreciated!

 

Best,

Nigel

Hi @Nigel_Mayhew1 

 

If you are just looking for one type of string at a time you just need to chnage any occurrence of ZRET in my code to X5, L8 etc.

 

However if you need to look for ZRET and X5 and L8 etc at the same time, you'll need different code.

 

If you can supply some example data I can show you.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @Nigel_Mayhew1 

 

Those particular cases causing issues weren't in the original data but no problem, give me 10 minutes to work on it.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @Nigel_Mayhew1 

 

Download PBIX file with example below

 

Create a Custom Column in Power Query with this

 

 

= try List.Select(Text.Split([Reference], " "), each Text.Contains(_ , "ZRET")){0} otherwise null

 

 

PhilipTreacy_0-1730211256749.png

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Philip,

 

Thanks for your response!

 

It mostly works well, but I still have some issues with the results.

 

Here are a few examples:

 

ReferenceResult
DURCHG. MIT TA-N100640929_ ZRET23/000781ZRET23/000781
DURCHGEF. MIT TA-N100646558-ZRET19/00144254TA-N100646558-ZRET19/00144254
Durchg mit TA-N100642382- ZRTE18/0011958null
FAKTURIERT MIT TA-N100642382 _ZRET18/0011958_ZRET18/0011958
FAKTURIERT MIT TA-N100642383 ZRET19/0014424ZRET19/0014424
FALSCH ZRET23/0010338 SB_X201463782 _ ZRET23/0012143ZRET23/0010338
Fakaturiert mit TA-N100632170 ZRET19/0014457ZRET19/0014457
Fakturiert mit TA-N100632168  ZRET23/0003782ZRET23/0003782
TA-15559999ZRET00/0013631TA-15559999ZRET00/0013631

 

Can you please help?

 

Best,

Nigel

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.