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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
ali_hijazi
Partner - Master II
Partner - Master II

is there a better approach

Hello
I have this script snippet in Qlik; I just want to know if there is a better approach to this or is this fine?

if(Ceil(Today() - floor(CASE_CREATED_DATE)) <= 1, '1D',

if(Ceil(Today() - floor(CASE_CREATED_DATE)) > 1 and Ceil(Today() - floor(CASE_CREATED_DATE)) <= 2, '2D',

if(Ceil(Today() - floor(CASE_CREATED_DATE)) > 2 and Ceil(Today() - floor(CASE_CREATED_DATE)) <= 7, '1W',

if(Ceil(Today() - floor(CASE_CREATED_DATE)) > 7 and Ceil(Today() - floor(CASE_CREATED_DATE)) <= 14, '2W',

if(Ceil(Today() - floor(CASE_CREATED_DATE)) > 14 and Ceil(Today() - floor(CASE_CREATED_DATE)) < $(vAgeingMax1M), '1M',

if(Ceil(Today() - floor(CASE_CREATED_DATE)) >= $(vAgeingMax1M) and Ceil(Today() - floor(CASE_CREATED_DATE)) < $(vAgeingMax2M), '2M',

if(Ceil(Today() - floor(CASE_CREATED_DATE)) >= $(vAgeingMax2M) and Ceil(Today() - floor(CASE_CREATED_DATE)) < $(vAgeingMax3M), '3M',

if(Ceil(Today() - floor(CASE_CREATED_DATE)) >= $(vAgeingMax3M), '> 3M'))))))))

as CASE_AGE,

I can walk on water when it freezes
3 Replies
marcus_sommer

I think a pick(match()) would be better in regard to the overview and performance. It means something like:

pick(match(Ceil(Today() - floor(CASE_CREATED_DATE)), 0,1,2,3,...),

     '1D', '1D', ....)

- Marcus

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You could calculate the date difference first and then in a preceding load classify the date differences.

LOAD

     *,

     If( DateDiff <=1, '1D',

       If( DateDiff <=2, '2D'

         If( DateDiff <=7, '1W',

             ...etc... as CASE_AGE

     ;

LOAD

     ...lots of fields,

     Ceil(Today() - floor(CASE_CREATED_DATE)) as DateDiff

FROM

     ...source...

     ;


talk is cheap, supply exceeds demand
balabhaskarqlik

Minimize the expression by using variables, like

LET vDate = Ceil(Today() - floor(CASE_CREATED_DATE);

And use this.