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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
yvonne-c
Creator
Creator

Value of Previous date, then assign status

I am trying to look at the current record and the previous record

My data looks like this:

IDDateHeadScore
1226-04-201611
1226-04-201640
1226-04-201670
1226-04-201680
1226-04-2016100
1226-04-2016

13

0
1209-12-201511
1208-08-201540
1209-12-201570
1209-12-201580

I have managed to get the previous date by creating the following in the script:

load farm_ID,

Head,

Date(Max(Date)) as MaxDate,

Date(Max(Date,2))as MaxDate2

Resident Mobility

Group by farm_ID, Head;

maxdate.JPG

Now I need to get the score for the previous date in the next column.

I just cannot find the expression to make this work correctly, can anybody help?!

When this column is complete I want to assign a status based on the current and previous score.

So if the current score = 0 and the previous score = 0 the result would be 'Clear',

Any help appreciated!

1 Solution

Accepted Solutions
sunny_talwar

May be this?

Table:

LOAD ID,

    Date,

    Head,

    Score

FROM

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

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

FinalTable:

LOAD *,

  If(Score = 0 and Previous_Score = 0, 'Clear') as Flag;

LOAD ID,

  Date,

  Head,

  Score,

  If(ID = Peek('ID') and Head = Peek('Head'), Peek('Date')) as Previous_Date,

  If(ID = Peek('ID') and Head = Peek('Head'), Peek('Score')) as Previous_Score

Resident Table

Order By ID, Head, Date asc;

DROP Table Table;


Capture.PNG

View solution in original post

6 Replies
sunny_talwar

May be this?

Table:

LOAD ID,

    Date,

    Head,

    Score

FROM

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

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

FinalTable:

LOAD *,

  If(Score = 0 and Previous_Score = 0, 'Clear') as Flag;

LOAD ID,

  Date,

  Head,

  Score,

  If(ID = Peek('ID') and Head = Peek('Head'), Peek('Date')) as Previous_Date,

  If(ID = Peek('ID') and Head = Peek('Head'), Peek('Score')) as Previous_Score

Resident Table

Order By ID, Head, Date asc;

DROP Table Table;


Capture.PNG

yvonne-c
Creator
Creator
Author

Thanks sunny, that works


I would like to add further conditions to the if statement, and put the result in the same 'flag' column, is that possible?

e.g.

If(Score = 2 and Previous_Score = 0, 'New') as Flag;

sunny_talwar

Ya that should be easy, right:

If(Score = 0 and Previous_Score = 0, 'Clear',

If(Score = 2 and Previous_Score = 0, 'New')) as Flag;

yvonne-c
Creator
Creator
Author

Easy when you know how!

You're a star, thanks

Ribeiro
Specialist
Specialist

Hi Summy,
I would like to try to help me in the question below😅

 

If DateVnd and QtdeVnd and CodProdVnd,
and CodProdCmp and VlrCmp and Null DtCmp,
Bring the last one as shown in the image below:

 

DateVndQtdeVndCodProdVndCodProdCmpVlrCmpDtCmp
15/01/20201410   
15/01/20201415   
16/01/202024108000,1516/01/2020
16/01/202024158010,1616/01/2020
17/01/20201410   
17/01/20201415   
18/01/202094108000,1118/01/2020
18/01/202094158010,1718/01/2020

Correct Result:

2020-04-17_11-01-09.png

Neves
Ribeiro
Specialist
Specialist

Fill in null values with the last value, as shown in the image.

Neves