Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I am trying to rename to the variable's values in Qlikview. May I know how to go about doing it? I had tried using "if" and "Rename" function but it doesn't seems to work.
For example
Original | Desired Output | |||||||||||
Mon | Tue | Wed | Thu | Fri | => | Mon | Tue | Wed | Thu | Fri | ||
Fruits | apple | orange | banana | pear | grapes | Fruits | 1 | 2 | 3 | 4 | 5 |
My expression:
if(Fruits='apple','1') or
if(Fruits='orange','2') or
....
if(Fruits='grapes','5')
Otherwise, if you are just looking for a nested if-statement expression to evaluate the 'Fruits' text to numeric, you can do something like this:
If(Fruits = 'apple', 1,
If(Fruits = 'orange', 2,
If(Fruits = 'banana', 3,
If(Fruits = 'pear', 4,
If(Fruits = 'grapes', 5)))));
I am not sure what you are trying to do. Do you want to rename the values during the script loading? Also, do you only have a few values (i.e. like 5-6) that you want to convert to numbers?
One approach might be do use WildMatch() like this:
LOAD WildMatch(Fruits,'apple','orange','banana','pear','grapes') as Fruits
FROM Table;
If Fruits = apple, WildMatch will return a 1
If Fruits = orange, WildMatch will return a 2
and so on...
Hi Lior,
Thanks for your reply. I am actually try to rename the variable values into names easier read by user. The initial variable value is a code X82-123 which I want to rename to be easier read value "apple".
I do not want to convert to number. I had around 15 values to convert.
Best regards,
Andy
Otherwise, if you are just looking for a nested if-statement expression to evaluate the 'Fruits' text to numeric, you can do something like this:
If(Fruits = 'apple', 1,
If(Fruits = 'orange', 2,
If(Fruits = 'banana', 3,
If(Fruits = 'pear', 4,
If(Fruits = 'grapes', 5)))));
Thanks Lior!! It works now!
Cheers,
Andy
You may want to look into ApplyMap(). You can load or create a table of code -to- friendly values.
For example:
// Code to Friendly values:
Map_Fruits:
Mapping LOAD * Inline
[
Code,Values
1,apple
2,orange
3,banana
4,pear
5,grapes
];
// ApplyMap when you load your data:
YourTable:
LOAD ApplyMap('Map_Fruits', Fruits) as FriendlyFruits
FROM Table;