Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
Modernize Your QlikView Deployment webinar, Nov. 3rd. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator II
Creator II

What's wrong in this expression in the script? Applymap & IF statement

Hi guys,

attached is a sample data file (is a personal/desktop) edition.

The output i want to obtain is the following:

if field3 = 1,  the first 5 number of field4 and the last 2 of the same field.

field3 is not in table, so i use applymap function.

Can someone help me?

Thanks,

Mattia

Labels (2)
6 Replies
Highlighted
MVP
MVP

Is this your expected output?

Capture.PNG

Highlighted
Creator II
Creator II

Hi Tresesco,

thanks for the message.

No, only in record with field2 01700000, o1600000 and ps000000 i want to see the value in new_field.

Because only in these record field3 = 1.

Highlighted
MVP
MVP

Try this:

If(ApplyMap('KEY_TO_FIELD3',[FIELD2],'n/a')=1, (Left([FIELD4],5) & ',' & Right([FIELD4],2))) as NEW_FIELD;

Highlighted
Creator II
Creator II

Yes, i've tried this expression and it works.

But, field3 in my file has been imported from a txt file.

The script is something like: [@18:20] as field3 and in the straight table i not see "1" but "001".

I think it probably be a problem of format but i don't know how to solve it!

Highlighted
MVP
MVP

001 is a text value here. You could get 1 from it using num(). Remove comma and try like:

If(ApplyMap('KEY_TO_FIELD3',[FIELD2],'n/a')=1, Num(Left([FIELD4],5) & Right([FIELD4],2))) as NEW_FIELD;

Highlighted
Creator II
Creator II

Sorry, but i don't understand the solution.

Now, in my file, new_field is correctly calculated.

The thing that is wrong is that the sw probably don't recognize that i want to see this value only in the records that have field3 = 1 !