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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

KPI with multiple nested conditions

Hello Qlik community.

I need to create KPI which calculates tickets (workorderid).

KPI has several nested conditions.

SQL query for this count looks as below:

SELECT COUNT(wo.WORKORDERID) FROM wo

LEFT JOIN ws ON wo.WORKORDERID=ws.WORKORDERID

LEFT JOIN sd ON ws.STATUSID=sd.STATUSID

LEFT JOIN wq ON wo.WORKORDERID = wq.WORKORDERID

LEFT JOIN qd ON wq.QUEUEID=qd.QUEUEID

LEFT JOIN tl ON wo.TEMPLATEID=tl.TEMPLATEID

WHERE

qd.QUEUENAME LIKE 'ServiceDesk%'

AND (tl.templatename like '%awarie%' OR tl.templatename like '%default%' or tl.templatename like '%reset%')

AND wo.title not like '%probid%' and sd.ispending=0

AND wo.WORKORDERID NOT IN (SELECT wttd.workorderid FROM WorkOrderToTaskDetails wttd

                           LEFT JOIN TaskDetails td ON wttd.TASKID=td.TASKID

                           LEFT JOIN QueueDefinition qd ON td.GROUPID=qd.QUEUEID

                           WHERE qd.QUEUENAME NOT LIKE 'Servi%' or td.taskid is null) ;

KPI counts OK in version below:

Count({$<QUEUENAME={'ServiceDesk*'}, TEMPLATENAME={'*awarie*','*default*','*reset*'}, TITLE-={'*probid*'}, ISPENDING={'0'}>} Distinct WORKORDERID)

but whe I try to add two more conditions like below:

Count({$<QUEUENAME={'ServiceDesk*'}, TEMPLATENAME={'*awarie*','*default*','*reset*'}, TITLE-={'*probid*'}, ISPENDING={'0'},

         QUEUENAME-={'Servi*'} or Len(Trim(TASKID))=0>} Distinct WORKORDERID)

result is not OK.

As you see there is subquery which excludes some workorderids from count and I don't know how to write it in KPI script.

10 Replies
OmarBenSalem
Partner - Champion II
Partner - Champion II

Try this :

Count({$<QUEUENAME={"ServiceDesk*"}, TEMPLATENAME={"*awarie*","*default*","*reset*'", TITLE-={"*probid*"}, ISPENDING={'0'},

QUEUENAME={"=-{"Servi*"} or  Len(Trim(TASKID))=0"}       

>} Distinct WORKORDERID)


sunny_talwar
MVP
MVP

May be this

Count({$<QUEUENAME = {"=(WildMatch(QUEUENAME, 'ServiceDesk*') and not WildMatch(QUEUENAME, 'Servi*')) or Len(Trim(TASKID)) = 0"}, TEMPLATENAME = {'*awarie*','*default*','*reset*'}, TITLE -= {'*probid*'}, ISPENDING = {'0'}>} Distinct WORKORDERID)

Anonymous
Not applicable
Author

Omar,

I have modified a little your answear, added missing curly brackets }, right now it looks like this:

Count({$<QUEUENAME={'ServiceDesk*'}, TEMPLATENAME={'*awarie*','*default*','*reset*'}, TITLE-={'*probid*'}, ISPENDING={'0'}, QUEUENAME={"=-{"Servi*"} or  Len(Trim(TASKID))=0"}>} Distinct WORKORDERID)

but it gives nothing - not even zero. When I modified it again:

Count({$<QUEUENAME={'ServiceDesk*'}, TEMPLATENAME={'*awarie*','*default*','*reset*'}, TITLE-={'*probid*'}, ISPENDING={'0'}, QUEUENAME={"=-{'Servi*'} or  Len(Trim(TASKID))=0"}>} Distinct WORKORDERID)

I got zero in result.

I think problem is with condition

QUEUENAME={"=-{'Servi*'} or  Len(Trim(TASKID))=0"}

OmarBenSalem
Partner - Champion II
Partner - Champion II

Can u alter it as follow and try?

QUEUENAME={"=not wildMatch(QUEUENAME, 'Servi*' ) or  Len(Trim(TASKID))=0"}


sunny_talwar
MVP
MVP

From what I see, this won't still work... you cannot have two different set analysis on the same field omarbensalem

Anonymous
Not applicable
Author

Unfortunately your suggestion gives number over 3 times more than correct one

sunny_talwar
MVP
MVP

Would you be able to share a sample app to test this out?

Anonymous
Not applicable
Author

I think I can share qvf file with one sheet. I use data manager not load script.

Right now application is about 80MB. Is it a way to make it smaller or this size is OK?

sunny_talwar
MVP
MVP

I am not sure how to do it in Qlik Sense, but feel free to share 80MB doc.