Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Qlik Analytics Tour 2020 Online. Begins August 10th. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator III
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

Tags (1)
1 Solution

Accepted Solutions
Highlighted
Specialist
Specialist

Re: Creating new field and values in script

hi!

load

Temperature,

if(Temperature=0,'Freezing',

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

from ....

View solution in original post

6 Replies
Highlighted

Re: Creating new field and values in script

Try this:

Table:

LOAD *,

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

LOAD * Inline [

Temperature

0

12

100

30

25

1

0

100

];


Capture.PNG

Highlighted
Specialist
Specialist

Re: Creating new field and values in script

hi!

load

Temperature,

if(Temperature=0,'Freezing',

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

from ....

View solution in original post

Highlighted
Champion III
Champion III

Re: Creating new field and values in script

Hi,

Temprature:

LOAD *,

     If(Temperature = 0 , 'Freezing',

     IF(Temperature = 100, 'Boiling',

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

Load * Inline [

Temperature

0

12

100

30

25

1

0

100

];

Thanks,

V.

Highlighted
Partner
Partner

Re: Creating new field and values in script

Hi,

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

Try this:-

Temperature_Data:

LOAD *

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

;

LOAD * INLINE [

    Temperature

  

    0

  

    12

  

    100

  

    30

  

    25

  

    1

  

    0

  

    100

];

EDITED because I notice this same suggestion above

Highlighted
Specialist III
Specialist III

Re: Creating new field and values in script

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

Temprature:

LOAD *,

     If(Temperature <= 0 , 'Freezing',

     IF(Temperature >= 100, 'Boiling',

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

Load * Inline [

Temperature

0

12

100

30

25

1

0

100

];

Highlighted
Creator III
Creator III

Re: Creating new field and values in script

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