Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jessica_webb
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

1 Solution

Accepted Solutions
pokassov
Specialist
Specialist

hi!

load

Temperature,

if(Temperature=0,'Freezing',

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

from ....

View solution in original post

6 Replies
sunny_talwar

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

pokassov
Specialist
Specialist

hi!

load

Temperature,

if(Temperature=0,'Freezing',

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

from ....

vishsaggi
Champion III
Champion III

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.

Gabriel
Partner - Specialist III
Partner - Specialist III

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

nagaiank
Specialist III
Specialist III

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

];

jessica_webb
Creator III
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