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

srehman

Board Regular
Joined
Jan 4, 2020
Messages
210
Office Version
  1. 2016
Platform
  1. Windows
Hi Team,

I have used following approach but not working

Text.Select([Rawdata],{"A".."Z"}) Data(AD1022010A) Result(ADA) wrong I need (AD)
Text.Select([Rawdata],{"0".."9"})





Split text & number power query.xlsx
DE
1Required Result
2RawdataStarting Alphabet from left before numbers
3AD102201AAD
4AIRLAIRL
5AP0332010BAP
6ARILS78ARILS
Sheet1
 

Attachments

  • text split from left.PNG
    text split from left.PNG
    4.6 KB · Views: 6
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.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,786
Messages
6,174,548
Members
452,572
Latest member
KP53

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top