• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Split Non-digit to digit in a string in Excel 2016|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Split Non-digit to digit in a string in Excel 2016|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QuerySplit Non-digit to digit in a strin…
sp_PrintTopic sp_TopicIcon
Split Non-digit to digit in a string in Excel 2016
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
1
April 30, 2021 - 9:31 am
sp_Permalink sp_Print

Hi I know this can be easily done in Office 365 using Split Column then select non-digit to digit,  how about user who do not have O365

e.g.      123_BLK234-4-A-1

I had 180K of records with Blk,  block follow by number inside a string,  want to extract to Blk 123, Block 56,   Blk 142

current I am using Text.PostOf([Paht], "blk") to get the position then Text.Middle,  then delete those I don't want using List.cumulative (manually eye ball put in a list then Text.BeforeDelimiter

it tooks quite lot time for the query to run

is there a better way using other M-code (wildcard for non-digit,  digit)

Thank you !!!

sp_AnswersTopicSeeAnswer See Answer
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4513
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
May 2, 2021 - 9:17 pm
sp_Permalink sp_Print

Hi Chris,

It's tricky as I also have 365 and can't test it, but can you use Splitter.SplitTextByEachDelimiter and set BLK as the delimiter? Then you can split again by the hyphen delimiter.

Mynda

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
3
May 2, 2021 - 9:48 pm
sp_Permalink sp_Print

Hi Mynda,

Thanks for your reply and this is one workaround, however I got the following pattern and others

ABC_BLK-234ROOF-ARCH-1

BLK234 is what I want

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
4
May 3, 2021 - 12:40 am
sp_Permalink sp_Print

Hi Mynda,

Attached sample of dataset

first tab was using O365 non-digit to digit which was quite ideal but unfortunate all my user don't have O365

2nd tab I use Text.PositionOf to extract out "Blk" or "Block",  and currently I only need the number after Blk or block,  is there a way to identify the position of alphabet  or special character ( -, _,  : etc),  then text.beforeDelimiter of these alphabet or special character

Thank you !

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
5
May 3, 2021 - 2:34 am
sp_Permalink sp_Print

Hi Chris

See if this formula solution helps.

Sunny

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
6
May 3, 2021 - 5:06 pm
sp_Permalink sp_Print

Hi Sunny,

Thanks for your solution,  and using native excel will take very long to process the formulae,  and also the original raw pattern may have space in between the blk and the number that I want,  sometimes "-", "_" etc

I hope to achieve similar to non-digit to digit splitting using non-O365 PQ coding

Thank you very much !

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4513
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
7
May 3, 2021 - 5:43 pm
sp_Permalink sp_Print

Hi Chris,

What happens if you use the function returned by split by non digit in your earlier version of Excel? e.g. in Query Table1 (2) add a custom column with this formula:

= Table.SplitColumn(#"Added Custom", "Custom", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Custom.1", "Custom.2", "Custom.3", "Custom.4"})

Mynda

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
8
May 4, 2021 - 5:21 pm
sp_Permalink sp_Print

Hi Mynda,

in my Excel 2019 desktop version

Expression.Error: The name "Splitter.SplitTextByCharacterTransition" wasn't recognized.  Make sure it's spelled correctly

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1529
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
9
May 5, 2021 - 10:20 pm
sp_Permalink sp_Print

Hi Chris,

I've written a function in Power Query that takes your Custom Column and then extracts everything up to the first number to character transition.  So in your Custom Column you have Blk123BBZXT and my function gives you Blk123.

Here's the function code - check the attached file for your solution.

let

ExtractChars = (values as list) as list =>

let

Extract = List.Generate
(

()=> [Char = values{0}, counter = 1, nullval = 0],

each [counter] < List.Count(values),

each [ Char = if nullval < 2 then values{[counter]} else null,

counter = [counter] + 1,

nullval = if [nullval] = 0 then if List.Contains({"0".."9"}, values{[counter]}) then 1 else 0 else

if [nullval] = 1 then if not List.Contains({"0".."9"}, values{[counter]}) then 2 else 1 else 2
],

each [Char]
)

in
Extract

in
ExtractChars

Regards

Phil

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
10
May 6, 2021 - 10:56 am
sp_Permalink sp_Print

Hi Philip

Really appreciate your effort in building a custom PQ function, I think space, "-", "_" scenario you script didn't take into consideration, apologise for not covering all scenario of my actual datasets

blk 3

test Blk 124

blk-23

blk-1

Probably you can explain to me the place to amend,  am not sure I can do it myself if I encounter more scenerio that not cover by the scripts

 

Mynda :-   Do you have any online course on how to build custom function (PQ) like you guys uses,  really is very useful for unstructured data if we do not want to use Advanced analytics tool to transform those datasets

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1529
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
11
May 6, 2021 - 12:58 pm
sp_Permalink sp_Print

Hi Chris,

Yes, always best to include all scenarios 🙂

I just needed to make an adjustment to the loop counter in the function to this

each [counter] <= List.Count(values),

otherwise it works as is - see attached file.

Functions in PQ are just 'regular' queries that have been formatted slightly differently to take input parameters. I wrote a blog about this

Power Query Custom Functions • My Online Training Hub

The key to creating a function like the one I wrote here for you is knowing the in-built PQ functions and a good understanding of the M language

Power Query M function reference - PowerQuery M | Microsoft Docs

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
12
May 6, 2021 - 10:59 pm
sp_Permalink sp_Print

Hi Philip,

Thanks for all your help

Can you briefing explain the codes and I will try to digest and understand it,   so far didn't code (don't know how to also) such a complicated PQ code,  for normal bringing in number to square it or bringing in text for Text.Beforelimiter etc I can do it,  not for such cumulative count to check whether it is numeric or character,  very curious that how this codes know I want "Blk",  "block"

pardon me Philip

Thank you !

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Cassie Bernier
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 215
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Ngoc Qui Nguyen
Clement Mansfield
Rose .
Bindu Menon
Baruch Zemer
Purple RainbowBenefactor
MOTH Junkie
Forum Stats:
Groups: 3
Forums: 24
Topics: 6350
Posts: 27773

 

Member Stats:
Guest Posters: 49
Members: 32317
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.