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

Create a Flag

  T1:  

IdNameStatusRiskDate
100ABCOpenLow10/1/2014
100ABCClosedMedium3/2/2014
200DEFOpenLow1/1/2015
200DEFOpenMedium1/2/2015
200DEFClosedHigh1/3/2015
300XXXOpenHigh5/6/2015
300XXXOpenLow7/7/2015
300XXXClosedHigh8/9/2015
400YYYOpenLow1/2/2015
400YYYClosedMedium2/2/2015
500ZZZOpenLow2/3/2015
100ABCClosedHigh3/5/2014
100ABCClosedMedium3/3/2014
200DEFClosedLow1/4/2015

I have a Table T1 with above mentioned data

we need to show the Risk  for a Id changes from when we first receive the Id's risk  in the above table to when their Status changes to Closed

A flag needs to be added to know risk changes or not

Output:

   

IdNameStatusRiskDateRisk_Flag
100ABCOpenLow10/1/2014N
100ABCOpenMedium3/2/2014Y
100ABCOpenHigh3/5/2014Y
100ABCClosedMedium3/6/2014Y
200DEFOpenLow1/1/2015N
200DEFOpenMedium1/2/2015Y
200DEFOpenHigh1/3/2015Y
200DEFClosedLow1/4/2015Y
300XXXOpenHigh5/6/2015N
300XXXOpenLow7/7/2015Y
300XXXClosedHigh8/9/2015Y
400YYYOpenLow1/2/2015N
400YYYClosedMedium2/2/2015Y
500ZZZOpenLow2/3/2015N

Please help me to get the above output.

31 Replies
Not applicable
Author

We need to show the Risk  for a Id changes from when the  Status is Open in the above table to when their Status changes to Closed

Sorry for the Incorrect table T1.

Here is the updated table T1 with data:  

IdNameStatusRiskDate
100ABCOpenLow10/1/2014
100ABCOpenMedium3/2/2014
200DEFOpenLow1/1/2015
200DEFOpenMedium1/2/2015
200DEFOpenHigh1/3/2015
300XXXOpenHigh5/6/2015
300XXXOpenLow7/7/2015
300XXXClosedHigh8/9/2015
400YYYOpenLow1/2/2015
400YYYClosedLow2/2/2015
500ZZZOpenLow2/3/2015
100ABCOpenHigh3/5/2014
100ABCClosedMedium3/6/2014
200DEFClosedLow1/4/2015

The result would be

Fo ex:In the below result the risk has been changed from low->Medium->High->Medium
for a profile 100

100 low                     -

100 low->Medium    Y(changed)

100 Medium->High   Y(changed)

100 High->Medium   Y(changed)

IdNameStatusRiskDateRisk_Flag
100ABCOpenLow10/1/2014N
100ABCOpenMedium3/2/2014Y
100ABCOpenHigh3/5/2014Y
100ABCClosedMedium3/6/2014Y
200DEFOpenLow1/1/2015N
200DEFOpenMedium1/2/2015Y
200DEFOpenHigh1/3/2015Y
200DEFClosedLow1/4/2015Y
300XXXOpenHigh5/6/2015N
300XXXOpenLow7/7/2015Y
300XXXClosedHigh8/9/2015Y
400YYYOpenLow1/2/2015N
400YYYClosedLow2/2/2015N
500ZZZOpenLow2/3/2015N
Not applicable
Author

We need to show the Risk  for a Id changes from when the  Status is Open in the above table to when their Status changes to Closed

Sorry for the Incorrect table T1.

Here is the updated table T1 with data:  

IdNameStatusRiskDate
100ABCOpenLow10/1/2014
100ABCOpenMedium3/2/2014
200DEFOpenLow1/1/2015
200DEFOpenMedium1/2/2015
200DEFOpenHigh1/3/2015
300XXXOpenHigh5/6/2015
300XXXOpenLow7/7/2015
300XXXClosedHigh8/9/2015
400YYYOpenLow1/2/2015
400YYYClosedLow2/2/2015
500ZZZOpenLow2/3/2015
100ABCOpenHigh3/5/2014
100ABCClosedMedium3/6/2014
200DEFClosedLow1/4/2015

The result would be

Fo ex:In the below result the risk has been changed from low->Medium->High->Medium
for a profile 100

100 low                     -

100 low->Medium    Y(changed)

100 Medium->High   Y(changed)

100 High->Medium   Y(changed)

IdNameStatusRiskDateRisk_Flag
100ABCOpenLow10/1/2014N
100ABCOpenMedium3/2/2014Y
100ABCOpenHigh3/5/2014Y
100ABCClosedMedium3/6/2014Y
200DEFOpenLow1/1/2015N
200DEFOpenMedium1/2/2015Y
200DEFOpenHigh1/3/2015Y
200DEFClosedLow1/4/2015Y
300XXXOpenHigh5/6/2015N
300XXXOpenLow7/7/2015Y
300XXXClosedHigh8/9/2015Y
400YYYOpenLow1/2/2015N
400YYYClosedLow2/2/2015N
500ZZZOpenLow2/3/2015N
Not applicable
Author

We need to show the Risk  for a Id changes from when the  Status is Open in the above table to when their Status changes to Closed

Sorry for the Incorrect table T1.

Here is the updated table T1 with data:  

IdNameStatusRiskDate
100ABCOpenLow10/1/2014
100ABCOpenMedium3/2/2014
200DEFOpenLow1/1/2015
200DEFOpenMedium1/2/2015
200DEFOpenHigh1/3/2015
300XXXOpenHigh5/6/2015
300XXXOpenLow7/7/2015
300XXXClosedHigh8/9/2015
400YYYOpenLow1/2/2015
400YYYClosedLow2/2/2015
500ZZZOpenLow2/3/2015
100ABCOpenHigh3/5/2014
100ABCClosedMedium3/6/2014
200DEFClosedLow1/4/2015

The result would be

Fo ex:In the below result the risk has been changed from low->Medium->High->Medium
for a profile 100

100 low                     -

100 low->Medium    Y(changed)

100 Medium->High   Y(changed)

100 High->Medium   Y(changed)

IdNameStatusRiskDateRisk_Flag
100ABCOpenLow10/1/2014N
100ABCOpenMedium3/2/2014Y
100ABCOpenHigh3/5/2014Y
100ABCClosedMedium3/6/2014Y
200DEFOpenLow1/1/2015N
200DEFOpenMedium1/2/2015Y
200DEFOpenHigh1/3/2015Y
200DEFClosedLow1/4/2015Y
300XXXOpenHigh5/6/2015N
300XXXOpenLow7/7/2015Y
300XXXClosedHigh8/9/2015Y
400YYYOpenLow1/2/2015N
400YYYClosedLow2/2/2015N
500ZZZOpenLow2/3/2015N
sunny_talwar

Try this:

Table:

LOAD Id,

     Name,

     Status,

     Risk,

     Date

FROM

[https://community.qlik.com/thread/216412]

(html, codepage is 1252, embedded labels, table is @9);

FinalTable:

LOAD *,

  If(Id = Peek('Id'), If(Risk <> Peek('Risk'), 'Y', 'N'), 'N') as Risk_Flag

Resident Table

Order By Id, Date;

DROP Table Table;


Capture.PNG

Kushal_Chawda

Data:

LOAD Id,

    Name,

    Status,

    Risk,

    Date

FROM

[https://community.qlik.com/thread/216412]

(html, codepage is 1252, embedded labels, table is @1);

Final:

LOAD Id,

    if(Id <> previous(Id) or  (Id = previous(Id) and Risk= previous(Risk)),'N','Y') as Risk_Flag,

    Name,

    Status,

    Risk,

    Date

Resident Data

order by Id, Date;

Drop Table Data;

Not applicable
Author

  Could you please help me to get the same output if we have data like below  

IdNameStatusRiskDate
100ABCOpenLow10/1/2014
100ABCOpenMedium10/1/2014
200DEFOpenLow1/1/2015
200DEFOpenMedium1/1/2015
200DEFOpenHigh1/1/2015
300XXXOpenHigh5/6/2015
300XXXOpenLow5/6/2015
300XXXClosedHigh8/9/2015
400YYYOpenLow1/2/2015
400YYYClosedLow2/2/2015
500ZZZOpenLow2/3/2015
100ABCOpenHigh10/1/2014
100ABCClosedMedium3/6/2014
200DEFClosedLow1/4/2015
Not applicable
Author

Could you please help me to get the same output if we have data like below  

IdNameStatusRiskDate
100ABCOpenLow10/1/2014
100ABCOpenMedium10/1/2014
200DEFOpenLow1/1/2015
200DEFOpenMedium1/1/2015
200DEFOpenHigh1/1/2015
300XXXOpenHigh5/6/2015
300XXXOpenLow5/6/2015
300XXXClosedHigh8/9/2015
400YYYOpenLow1/2/2015
400YYYClosedLow2/2/2015
500ZZZOpenLow2/3/2015
100ABCOpenHigh10/1/2014
100ABCClosedMedium3/6/2014
200DEFClosedLow1/4/2015
Kushal_Chawda

It will work for this data also as far as the logic is not changed.

sunny_talwar

What is the difference between this data and previously shared data?

Not applicable
Author

Previously,we have different dates on various risk ratings,status and we were ordering on Id,Date

currently,we have same date on open status and for different risk raings and the date changed on closed status