Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
shruthibk
Creator
Creator

Row wise comparision

Hi All,

can anybody help me to solve requirement for below data

 

RiskIssuesstatus
12closed
13open
56closed
57closed
911open
913closed

If Risk ID=1 and Issue id 2 (Closed) and Issue id 3(Open) it should exclude Issue ID 2 and show Issue ID 3.

If Risk ID=5 and Issue id 6 (Closed) and Issue id 7(Closed) it should display both the issue IDs(6 & 7).

How can i achieve this in script?


Thanks in advance

1 Solution

Accepted Solutions
techvarun
Specialist II
Specialist II

The below code will give you the output.

but i am not sure i understood the business logic here

New:

LOAD *, If(status = 'open',1,0) as statusnew INLINE [

    Risk, Issues, status

    1, 2, closed

    1, 3, open

    5, 6, closed

    5, 7, closed

    9, 11, open

    9, 13, closed

];

inner join

Load Sum(statusnew) as Flag ,Risk Resident New Group by Risk;

Load Risk,Issues, status Resident New Where (Flag > 0 and status = 'open') OR ( Flag =0 and status ='closed');

DROP Table New;

View solution in original post

7 Replies
shruthibk
Creator
Creator
Author

RiskIssuesstatus
13open
56closed
57closed
911open

Expected output

prma7799
Master III
Master III

Try like this

Test:

LOAD * Inline [

Risk, Issues, status

1 ,2, closed

1 ,3 ,open

5 ,6 ,closed

5, 7 ,closed

9 ,11 ,open

9 ,13 ,closed

];

New:

LOAD * , 

if ( Risk = 1 or  Issues = 3 ,  'Open',

if ( Risk = 5 or   Issues = 6  or  Issues = 7 , 'Closed', 'Open'

))  as NewStatus

Resident Test

;

DROP Table Test;

techvarun
Specialist II
Specialist II

The below code will give you the output.

but i am not sure i understood the business logic here

New:

LOAD *, If(status = 'open',1,0) as statusnew INLINE [

    Risk, Issues, status

    1, 2, closed

    1, 3, open

    5, 6, closed

    5, 7, closed

    9, 11, open

    9, 13, closed

];

inner join

Load Sum(statusnew) as Flag ,Risk Resident New Group by Risk;

Load Risk,Issues, status Resident New Where (Flag > 0 and status = 'open') OR ( Flag =0 and status ='closed');

DROP Table New;

techvarun
Specialist II
Specialist II

If I understand your logic clearly you need to display the open items for each Risk by for any Risk ID if All the Issues are closed then you need to display the closed entries too... Am i right?

sunny_talwar

May be this

Table:

LOAD * INLINE [

    Risk, Issues, status

    1, 2, closed

    1, 3, open

    5, 6, closed

    5, 7, closed

    9, 11, open

    9, 13, closed

];

Right Join (Table)

LOAD Risk,

If(SubStringCount(Concat('|' & status & '|'), 'open'), 'open', 'closed') as status

Resident Table

Group By Risk;

shruthibk
Creator
Creator
Author

Hi Sunny your understanding is correct but i need left join because this is a sample data i have posted, in actual application there are many fields

sunny_talwar

You need a left join? Not sure I understand?