Split Alphabet only from Left Just before Numbers only in Power query

srehman

Board Regular
Joined
Jan 4, 2020
Messages
140
Office Version
2016
Platform
Windows
Yes i have done by Post #5 if you have text like DAM001 result is DD it should be DAM ,
Bc subtract -1 , if i removed this 1 it will effect on other data.
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,757
RawdataRawdataText Range
AD102201AAD102201AAD
AIRLAIRLAIRL
AP0332010BAP0332010BAP
ARILS78ARILS78ARIL
DD3403A1DD3403A1DD
DAM001DAM001DAM

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    Number = Table.AddColumn(Source, "Number", each Text.Select([Rawdata],{"0".."9"})),
    LenRaw = Table.AddColumn(Number, "Length", each Text.Length([Rawdata]), Int64.Type),
    LenNum = Table.AddColumn(LenRaw, "Length.1", each Text.Length([Number]), Int64.Type),
    Subtract = Table.AddColumn(LenNum, "Subtraction", each [Length] - [Length.1], type number),
    IF = Table.AddColumn(Subtract, "IF", each if [Length.1] = 0 or [Length.1] = [Subtraction] then [Subtraction] else [Subtraction]-1),
    Range = Table.AddColumn(IF, "Text Range", each Text.Middle([Rawdata], 0, [IF]), type text),
    TSC = Table.SelectColumns(Range,{"Rawdata", "Text Range"})
in
    TSC
 
Last edited:

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,757
I think it can be applied to all your cases

RawdataTR
AD102201AAD
AIRLAIRL
AP0332010BAP
ARILS78ARILS
DD3403A1DD
DAM001DAM
POL321APOL
WEIRD455555DDD123WEIRD

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    Trim = Table.AddColumn(Source, "Trim", each Text.Trim([Rawdata], {"0".."9"})),
    Number = Table.AddColumn(Trim, "Number", each Text.Select([Trim], {"0".."9"})),
    TR = Table.AddColumn(Number, "TR", each Text.Replace([Trim],[Number], "|")),
    ETBD = Table.TransformColumns(TR, {{"TR", each Text.BeforeDelimiter(_, "|"), type text}}),
    TSC = Table.SelectColumns(ETBD,{"TR"})
in
    TSC
 

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,757
another approach
this is very good fun to extracting the assumed criteria :biggrin:
RawdataResult
AD102201AAD
AIRLAIRL
AP0332010BAP
ARILS78ARILS
DD3403A1DD
DAM001DAM
POL321APOL
WEIRD455555DDD123WEIRD
ODD5QWERTY66ZXCVB9988ODD
XYZ33WAB543ASD128SSD555XYZ

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Number = Table.AddColumn(Source, "FC", each Text.Select([Rawdata],{"0".."9"})),
    FC = Table.TransformColumns(Number, {{"FC", each Text.Start(_, 1), type text}}),
    Pos = Table.AddColumn(FC, "Pos", each Text.PositionOf([Rawdata], [FC])),
    Range = Table.AddColumn(Pos, "Text Range", each Text.Middle([Rawdata], 0, [Pos]), type text),
    IF = Table.AddColumn(Range, "Result", each if [Pos] = 0 then [Rawdata] else [Text Range]),
    TSC = Table.SelectColumns(IF,{"Result"})
in
    TSC
 

srehman

Board Regular
Joined
Jan 4, 2020
Messages
140
Office Version
2016
Platform
Windows
Awesome approaches both are working, I promised i will not add anymore scenarios in this post.:):)

Lot of thanks for Sandy & Rich. for your time & kind support.

The habit of sharing knowledge 100% will increase our knowledge more. This is real truth.

Take Care
 

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,757
You are welcome

I promised i will not add anymore scenarios in this post
You can add more and bigger strings but before you post, test it with M from post#24 where you can see it works with longer strings
the rule for this is: start with letters and then numbers - it doesn't matter what will be after that
 

Watch MrExcel Video

Forum statistics

Threads
1,102,145
Messages
5,484,990
Members
407,478
Latest member
wsupaul

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top