Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Case When Help

Hi All

I'm new to qlikview. Can somebody help me explain why this case statement doesn't work in the back end?

CASE

WHEN vhl_1_age = 0 THEN 'A'

WHEN vhl_1_age = 1 THEN 'B'

ELSE vhl_1_age

END  AS   vhl_1_age_Grouping

Thanks

5 Replies
Anonymous
Not applicable
Author

Hi James,

The when case should be used only with full scripts, example:

Case var 1

When 2

load * from table1

when 3

Load * from table2

Etc..

For what you are trying to do, use the if statement.

Regards

israrkhan
Specialist II
Specialist II

hi, i think ' ' mark are missing

CASE

WHEN vhl_1_age = 0 THEN 'A'

WHEN vhl_1_age = 1 THEN 'B'

ELSE 'vhl_1_age'         ....was missing

END  AS   vhl_1_age_Grouping

.......................................................................

below is working in mytable

SELECT productid, productname, unitprice,

CASE

WHEN unitprice < 20.00 THEN 'Low'

WHEN unitprice < 40.00 THEN 'Medium'

WHEN unitprice >= 40.00 THEN 'High'

ELSE 'Unknown'

END AS pricerange

FROM Production.Products;

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You can try using a nested if or a pick statement:

LOAD

if(vhl_1_age=0,'A', if(vhl_1_age=1,'B',vhl_1_age)) as vhl_1_age_Grouping

FROM ...mysource...;

LOAD

pick(vhl_1_age+1),vhl_1_age,'A','B') as vhl_1_age_Grouping

FROM ...mysource...;


talk is cheap, supply exceeds demand
Not applicable
Author

I want to do the same in the script so i do not have to convert the values in every graph, but the read fail. I have tried it directly in SQL manager and it works, but not in the script.

Have tried i bit different versions, but it fails every time.

load *

;

SQL

select

f.BirthDate As Fødselsdag,

f.ExtType as Skyldnertype,

CASE

         WHEN f.ExtType = '1' THEN 'Privat'

         WHEN f.ExtType =  '2' THEN 'Bedrift'

         WHEN f.ExtType =  '3' THEN 'ENK'

         else  'Ukjent'

         end  as Skyldnertype,

d.StartedDate as KampanjeStart,

Not applicable
Author

And as I read my own code I found what was wrong. Same name in two settings worked fine in SQL manager, but not in the script.

Now i changed name og one field and it works fine, just as I wanted.