Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Right, Left, Mid in the script

Hi,

I have a KeyField with the Material Number and Plant as below.

999999020-0310

How can I seperate the two Fields. The Material Number length is not fixed. it can be from 3 Digits to more than 10 or more.

I can get the Plant Number with this code

right(Field,4) as Plant

Somecombination of right() ands left() shoould give me result. Can anyone help

Thanks

Sravan

1 Solution

Accepted Solutions
Not applicable
Author

Hi

You can get it using below exp

left(Field,len(Field)-right(Field,5))

Thanks & Reagrds

View solution in original post

10 Replies
Not applicable
Author

Hi

You can get it using below exp

left(Field,len(Field)-right(Field,5))

Thanks & Reagrds

IAMDV
Master II
Master II

Sravan - Use the SUBFIELD function and split by delimiter.

=SubField(FieldName, '-')

Hope this helps...

Cheers - DV

Not applicable
Author

Hi Upendra,

with little correction, your code worked. Thanks:)

left(field,len(field)-len(right(field,5)))

@ deepak,

with Subfield I get the field split in to Material and Plant but I cant apply left() or right() to get the fields

Anyway thanks

sravan

IAMDV
Master II
Master II

Excellent! I am glad that you got it working.

Just a quick word of caution! I am very sure you are aware of this... If the number of characters in the Plant Field changes in coming years, you might have incomplete data. If this is case then I would recommend making the function more robust.

Cheers - DV

Not applicable
Author

Thanks Deepak,

I know that but I hope that there is a better solution than this! For Now I will take this.

Regards

Sravan

nathanfurby
Specialist
Specialist

DV is correct. You should use the SubField function. It's much easier and also more robust:

SubField(Field,'-',1) AS MaterialNumber

SubField(Field,'-',2) AS Plant

IAMDV
Master II
Master II

Sravan - Just thought this might be more robust solution.

To get the Material Number use this expression:

=Left(UniqueNumber, FindOneOf(UniqueNumber, '-') - 1)

To get the Plant Number use this expression:

=Right(UniqueNumber, Len(UniqueNumber) - FindOneOf(UniqueNumber, '-'))

With these expressions you don't have to worry about the number of characters. I mean you are not dependant on the number of characters in the field, rather you will be using the properties of the Field.

I hope this is clear enough for your understanding. Let me know if you need further explanation.

Cheers - DV

IAMDV
Master II
Master II

Thanks NathanFurby.

I thought the same! It is good practice to use these kind of expression in the Load Script compared to the Field expressions.

Cheers - DV

nathanfurby
Specialist
Specialist

Yep - no need for complicated string functions. Subfield will do the job Big Smile