Announcements
Product Release Webinar: Qlik Insider airing December 6! REGISTER TODAY!
cancel
Showing results for
Did you mean:
Creator III

## Creating new field and values in script

Hi,

I'm sure this must be really straightforward, but I can't find a solution anywhere!

I have a field with lots of different values, and I want to use these values to create a new field, with only 3 values, in the script.

E.g.

Temperature

0

12

100

30

25

1

0

100

I want a new field called 'Description' that gives the value 'Freezing' if the Temp is = 0, 'Boiling' if the Temp is = 100, and 'Between' if the the Temp is neither 0 or 100.

Thanks,
Jess

1 Solution

Accepted Solutions
Specialist

hi!

Temperature,

if(Temperature=0,'Freezing',

if(Temperature=100,'Temp=100', 'Between')) as Temp

from ....

6 Replies
MVP

Try this:

Table:

Pick(Match(Temperature, 0, 100, Temperature), 'Freezing', 'Boiling', 'Between') as Description;

Temperature

0

12

100

30

25

1

0

100

];

Specialist

hi!

Temperature,

if(Temperature=0,'Freezing',

if(Temperature=100,'Temp=100', 'Between')) as Temp

from ....

Champion III

Hi,

Temprature:

If(Temperature = 0 , 'Freezing',

IF(Temperature = 100, 'Boiling',

If(Temperature >0 AND Temperature < 100, 'Between'))) As Description;

Temperature

0

12

100

30

25

1

0

100

];

Thanks,

V.

Partner - Specialist III

Hi,

I will advocate for using PICK() and MATCH() Function simply for load performance.

Try this:-

Temperature_Data:

,PICK(MATCH(Temperature, 0 , 100 , Temperature),'Freezing','Boilong','Between')    AS Description

;

Temperature

0

12

100

30

25

1

0

100

];

EDITED because I notice this same suggestion above

Specialist III

You may use the following script in order to take care of temperatures other than 0 and 100 correctly.

Temprature:

If(Temperature <= 0 , 'Freezing',

IF(Temperature >= 100, 'Boiling',

If(Temperature >0 AND Temperature < 100, 'Between'))) As Description;

Temperature

0

12

100

30

25

1

0

100

];

Creator III
Author

Hi,

Thanks for everyone's responses.

This solution is perfect (I should have mentioned that the list of different temperatures was a lot longer than my example, so an inline table wouldn't work).

Thanks again,

Jess

Community Browser