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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
khisla
Helper I
Helper I

Extract part of text string

I have a column with a text sting that I need to extract the store number

 

Test StringExpected Result
232 אאוטלט מול הריםנוף הגליל IL213IL213
232 אאוטלט מול הריםנוף הגליל IL213IL213
227 אדידס אאוטלט ביג ירכא IL208IL208
235 IL216 זכרון יעקבIL216
235 IL216 זכרון יעקבIL216
250 אאוטלט חוצות המפרץ חיפה IL225IL225
222 אדידס אאוטלט בילו IL204IL204
  
7 REPLIES 7
techies
Solution Sage
Solution Sage

Hi @khisla please try this custom column in power query editor

 

= if Text.Contains([Test String], "IL")
then Text.Middle([Test String], Text.PositionOf([Test String], "IL"), 5)
else null

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978
EricVieira
Regular Visitor

Text.Middle(Text.Select([Test String], {"A".."Z", "0".."9"}), Text.PositionOfAny(Text.Select([Test String], {"A".."Z", "0".."9"}), {"IL"}), 5)


Text.Middle(Text.RegexReplace([Test String], ".*(IL\d{3}).*", "$1"), 0, 5)
khisla
Helper I
Helper I

Not sure I understand the calculation.  The store number does not sit within the same text location in each row therefore not sure the 5 is the same for each row.  What do I enter for Table [String]?

 

OK, sorry I thought it was always at the end

 

Table[String] is the column from where you need to extract the store

 

In this case:

Store Number = 
VAR pos = FIND ( "IL", Table[String] )
RETURN MID ( Table[String], pos, 5 )
 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Did not work.  

I have this Text.Start(Text.AfterDelimiter([סניף],"IL"),3) which worked however need to also include the IL portion.  Any idea?

What you are using is an M functon (Power Query)

This is the DAX section of the forum so I suggested a DAX formula for a calculated column, please try that and if it works marks this as a solution.

 

If you need a Power Query solution, pls post there so you get also a PQeury solution

Thanks

FBergamaschi
Resolver V
Resolver V

Create a calculate column

 

Store Number = RIGHT ( Table[String], 5 )

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.