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

How to conditionally remove last Char from a text field ?

Hi

I have a data field that as an example contains:-

CB12123A

REQ03456

AT1234B

AT1234A

The A or B in the last Char cannot be guaranteed to always be in the same char position.

What I need to do is strip off the last digit if it is an Alpha Character A or B so I end up with.

CB12123

REQ03456

AT1234

AT1234

I have tried using If Statements with Right and PurgeChar but it does not give desired results.

Any help from the QV community would be welcome

1 Solution

Accepted Solutions
MayilVahanan

HI

Try like this

=if(match(right('AT1234B',1),'A','B'),Left('AT1234B',len('AT1234B')-1))

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

4 Replies
MayilVahanan

HI

Try like this

=if(match(right('AT1234B',1),'A','B'),Left('AT1234B',len('AT1234B')-1))

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this script

LOAD

    Text,

    If(Match(Right(Text, 1),'A','B'), Left(Text, len(Text)-1), Text) AS FormattedText;

LOAD * INLINE [

Text

CB12123A

REQ03456

AT1234B

AT1234A

];

Hope it helps you.

Regards,

jagan.

Not applicable
Author

Hi Mayil

Very ellegant solution worked fine

Not applicable
Author

Thanks Jagan

I am impressed with the wealth of knowledge there is out there in the Qlikview Community