Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Can CASE statement be used in QV?

I used to use CASE statement in SQL SELECT statements, what would be the equivalent expression in QV - thanks in advance

10 Replies
Anonymous
Not applicable
Author

Hi!

With mappings, you have the option to define the default value when you apply it:

ApplyMap ('MapName', MapField, 'defaultIfNull');

In the default value, you can add another mapping expression. So if you don't have a match in the first map, you can use the second map. Or you could concatenate 2 mapping tables into one.

If you have more complex stuff with a lot of rules, then the best approach woult be to join the main table the other needed tables with the values you want, to a temp table:

TempTable:

Select field1, field2, field3 from yourmaintable.

Left Join

Load field3, field4  resident maptable1; /*These are not qlikview maps, but normal tables that you will delete in the end of the code.*/

Left Join

Load  field3, field5  resident maptable2;

Then with a load resident of the temp table, insert your logic to select the

FinalTable:

Load *, if(isnull(Field4), Field5,Field4) as yourfieldName;

Load * resident TempTable;

Drop Fields Field5, Field4 from FinalTable;

Drop tables TempTable, maptable1, maptable2;

Its very important that you use a left Join, in order to mantain the whole data from the temp table.

Hope it helps.