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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
khisla
Helper II
Helper II

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
  
2 ACCEPTED SOLUTIONS
techies
Super User
Super User

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 | DP-700 Certified

View solution in original post

Hi @khisla please check this

 

techies_0-1752642554170.png

 

Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

View solution in original post

13 REPLIES 13
v-tejrama
Community Support
Community Support

Hi @khisla ,

Thanks for reaching out to the Microsoft fabric community forum.

 

You can do this easily in Power BI Desktop without writing any M code. First, I loaded my data into Power BI, where I had a column called "Test String" containing long texts like "Adidas Outlet IL208" or "Zichron Yaakov IL216". Then, I went to the Data view, clicked on Modeling > New Column, and wrote this simple DAX:

 

Here is the DAX  used:

 

StoreNumber =
VAR StartPos = SEARCH("IL", 'YourTableName'[Test String], 1, -1)
RETURN IF(StartPos > 0, MID('YourTableName'[Test String], StartPos, 5), BLANK())


This formula searches for the position of "IL" and pulls the next 5 characters (like "IL216"). Once the column was created, I went to Report view and added a Table visual where I placed both Test String and the new StoreNumber column. This helped me clearly see whether the store number was extracted correctly. You can also use a Bar chart or Matrix visual if you want to count how many times each store number appears. For easy filtering, I also added a Slicer with StoreNumber. Everything worked smoothly using only DAX, no Power Query needed.

 

Please find the attached pbix file for your reference.


Best Regards,
Tejaswi.
Community Support

 

 

techies
Super User
Super User

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 | DP-700 Certified

I used this for another purpose but am getting an error message for cells which do not include a value or value if null.  How can I adjust accordingly?

 

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

Got error

Hi @khisla please check this

 

techies_0-1752642554170.png

 

Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

I used this for another purpose but I am getting an error message when the cells does not contain a value or is null.  How can I adjust this accordingly for a null value scenario.

 

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

Thanks!!! This worked perfectly.

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 II
Helper II

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
Super User
Super User

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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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