Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Rename a field in a Script with if

Hi,

I'ld like to rename a field in my script like that :

LOAD

    Sta as [Sta Field];

        IF(Sta= 'A' , 'Active',

        IF(Sta= 'B', 'Beginning',

        IF(Sta= 'C', 'Close')));

SQL SELECT Sta

    FROM TABLE;

But that's didn't work. Can you give me some advice pliz ?

1 Solution

Accepted Solutions
Not applicable
Author

Erwan,

Map1:

Mapping LOAD * INLINE [

Colkey, ColReplace

A, Active

B, Beginning

C, Close]

(the names of the columns do not matter)

Afterwards,

Load  .....,

ApplyMap('Map1', STA) as xxx

.....

Assuming that STA is A, B or C. If sth else, Applymap will return null() except if you set a 3d argument, sth like 'STA not found'.

Fabrice

View solution in original post

8 Replies
Not applicable
Author

Hi try like this,

Load

Sta as [sta Field];

if(match(sta='A','Active',

IF(match(Sta= 'B', 'Beginning',

        IF(match(Sta= 'C', 'Close')));

Not applicable
Author

Hi Erwan

First of all remove semicolon after [Sta Field]

Sta as [Sta Field];


Then put some column name for the column with If statements


IF(Sta= 'C', 'Close'))) AS [Sta Name];


You also may like you use mapping table/applymap for this instead of nested If


Lukasz

Not applicable
Author

Erwan,

Do you want to rename field or field value ?

If it is the value, you can use ApplyMap() function.

First you load a 2 field table with the Mapping Load statement. You will have A - Active, B - Beginning ...

Second, you load your table & your field :

LOAD .... applymap('MapTable', Value) as XXXX

(the value is A, B, C : the first column of the mapping table)

Fabrice

nizamsha
Specialist II
Specialist II

Just as an  Example

TableA:

LOAD * Inline [

Sta

A

B

C

];

LOAD Sta as Sta1 ,if(Sta='A','Active',IF(Sta='B','Begining',IF(Sta='C','Cancel'))) as Sta2 Resident TableA;

Not applicable
Author

Thx for your help. You are right, I want to rename/change my value. I'll try the applymap function.

In my list, I've this :

Sta :

  • A
  • B
  • C

And I want this :

  • Active
  • Beginning
  • Close

Btw I'm a beginner on QlikView and i'm not very proud of my English.

Not applicable
Author

Erwan,

Map1:

Mapping LOAD * INLINE [

Colkey, ColReplace

A, Active

B, Beginning

C, Close]

(the names of the columns do not matter)

Afterwards,

Load  .....,

ApplyMap('Map1', STA) as xxx

.....

Assuming that STA is A, B or C. If sth else, Applymap will return null() except if you set a 3d argument, sth like 'STA not found'.

Fabrice

Not applicable
Author

Hi Erwan,

Just replace the semi colon with comma, after the [Sta Field] and then try it. It should work.

corrected script

LOAD

    Sta as [Sta Field],

        IF(Sta= 'A' , 'Active',

        IF(Sta= 'B', 'Beginning',

        IF(Sta= 'C', 'Close')));

SQL SELECT Sta

    FROM TABLE;

Not applicable
Author

Work great!

Thank you a lot Fabrice.