Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
deepakqlikview_123
Specialist
Specialist

Code

Hi all,

Can you please suggest what would be optimized code for code given below.

if(FuelType='Diesel' or FuelType='DIESEL','Diesel',If(FuelType='LPG','LPG',If(FuelType='CNG','CNG')))as FuelType

If fuel type is Diesel or DIESEL then i need to display DIESEL or if fuel type is CNG then CNG and if LPG then LPG.

Thanks,

Deepak

6 Replies
its_anandrjs

You can try with

if(Match(FuelType='Diesel','DIESEL'),'DIESEL',

If(Match(FuelType='LPG'),'LPG',

If(Match(FuelType='CNG'),'CNG'))) as FuelType


preminqlik
Specialist II
Specialist II

Load *,

upper(trim(FuelType) )              as          NewFuelType

from path;

its_anandrjs

Another way is

Load

Trim(if(Match(FuelType='Diesel','DIESEL'),'DIESEL',

       If(Match(FuelType='LPG'),'LPG',

       If(Match(FuelType='CNG'),'CNG'))) ) as FuelType

From Location;

deepakqlikview_123
Specialist
Specialist
Author

Hi Anand,

It is giving me syntax error.

NareshGuntur
Partner - Specialist
Partner - Specialist

Hi Deepak,

Try this

if(Upper(FuelType)='DIESEL','DIESEL',if(Upper(FuelType)='LPG','LPG',if(Upper(FuelType)='CNG','CNG')))

anbu1984
Master III
Master III

=if(Match(FuelType,'Diesel' ,'DIESEL','LPG','CNG'),Upper(FuelType))