Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I am writing if condition in script.
Is there any limit that we can use only this many if conditions in single column defination?
Regards,
Sadasiva
Hi Sada,
It would be handy if Qlik script supported a CASE or SWITCH type function for these scenarios, but I find an easy, and very maintainable and importantly efficient solution is to create a temporary mapping table and then use the applymap() function.
Here's the idea, give it a whirl:
T1:
LOAD * INLINE [
Min, Max, Name
551000, 551001, COGS - Credit Sales
502000, 502001, COGS - Cash Sales
];
GL_Names:
Mapping Load
Min + (iterno()-1) as GL_AccountNumber
,Name
Resident T1
While Min + (Iterno()-1) <= Max;
Drop table T1;
MainTable:
Load *,
ApplyMap('GL_Names',GL_AccountNumber) AS GL_Name
From DataSource;
Code is untested, but should give you a good idea on how you can solve the problem elegantly - not an IF statement in sight .