Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Mattia
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
tresesco
MVP
MVP

Is this your expected output?

Capture.PNG

Mattia
Creator II
Creator II
Author

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.

tresesco
MVP
MVP

Try this:

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

Mattia
Creator II
Creator II
Author

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!

tresesco
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;

Mattia
Creator II
Creator II
Author

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 !