Forum Discussion
Anonymous
4 years agoNot applicable
Extract last sequence of numerical value from string
I have a process that works but it is rather inelegant. I'm sure there must be a better way to do this. In a certain column, the last several characters might be numbers. If the length of a numbe...
- 4 years ago
You may use below in a custom column
= if Text.Select(Text.End([ColumnA],6),{"0".."9"})=Text.End([ColumnA],6) then Text.End([ColumnA],6) else if Text.Select(Text.End([ColumnA],5),{"0".."9"})=Text.End([ColumnA],5) then Text.End([ColumnA],5) else if Text.Select(Text.End([ColumnA],4),{"0".."9"})=Text.End([ColumnA],4) then Text.End([ColumnA],4) else nullEDIT - Another alternative construct is this which is more flexible
=[a=List.LastN(List.Transform(Text.ToList([ColumnA]),(x)=>if Text.Contains(Text.Combine({"0".."9"}),x) then x else null), each _ <> null), b=if List.Count(a)<4 then null else Text.Combine(a)][b]
Vijay_A_Verma
4 years agoMost Valuable Professional
You may use below in a custom column
= if Text.Select(Text.End([ColumnA],6),{"0".."9"})=Text.End([ColumnA],6) then Text.End([ColumnA],6)
else if Text.Select(Text.End([ColumnA],5),{"0".."9"})=Text.End([ColumnA],5) then Text.End([ColumnA],5)
else if Text.Select(Text.End([ColumnA],4),{"0".."9"})=Text.End([ColumnA],4) then Text.End([ColumnA],4)
else null
EDIT - Another alternative construct is this which is more flexible
=[a=List.LastN(List.Transform(Text.ToList([ColumnA]),(x)=>if Text.Contains(Text.Combine({"0".."9"}),x) then x else null), each _ <> null),
b=if List.Count(a)<4 then null else Text.Combine(a)][b]
- Anonymous4 years agoNot applicable
That's fantastic. Thank you!
I understand how the first approach works but I'm having trouble wrapping my mind around the second approach.
Would you explain how it works?