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: 
abc_18
Creator II
Creator II

How to insert the additional condition in the if statement

Hi,

 

My current code is as below:-

Sum(if(date(date#([WO created date],'YYYYMMDD'),'YYYYMMDD')
>
date(AddYears(date#(warrantydate,'YYYYMMDD'),1),'YYYYMMDD'),[Count WO],0))

 

which gives me values in number.

 

Now I have to insert additional conditional check in this code as :- [WO task code id]*={'T113','T114'}

How can I acheive this.

Thanks

Labels (1)
2 Replies
tresesco
MVP
MVP

Try like:

Sum( {<[WO task code id]*={'T113', 'T114'}>} if(date#([WO created date],'YYYYMMDD')>
AddYears(date#(warrantydate,'YYYYMMDD'),1),[Count WO],0))

Note: removed unnecessary formatting function date()

marcus_sommer

I think I would convert all dates-fields already within the script into real dates (maybe as additionally fields and if needed within an own calendar) so that no convertings within any UI calculations are neeeded. Further like Tresesco already mentioned for a numerical comparing is no formatting necessary.

Depending on your datamodel you might be also able to transfer the if-loop into the set analysis which then might be look like:

Sum({<[WO task code id]*={'T113', 'T114'}, 
[Count WO] = {"=[WO created date]>AddYears(warrantydate,1)"}
>} [Count WO])

Should this not be possible it's often better to use a: if(condition, sum(field)) instead of sum(if(condition, field)) for performance reasons.

- Marcus