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: 
marunio007
Contributor III
Contributor III

Adding a field with latest value and date

Hello,

I have 2 tables:

Visit:
Load * Inline [
Patient, VisitDate
1,2014-12-18
1,2015-04-09
1,2015-05-14
2,2014-01-24
2,2014-07-25
2,2015-01-23
]

;
ACR:
Load * Inline [
Patient, ACRDate, ACR
1,2014-08-12,24.1
1,2014-12-03,36.5
1,2015-04-02,12.8
1,2015-04-30,11.3
2,2014-01-17,41
2,2014-07-21,43.2
2,2016-01-21,34.4
]

For each visit I need to know what the last  ACR prior to the visit was and when.
I would like to attach 2 columns to table Visit: LastACRDate and LastACR.

So the Visit table will look like this:

PatientVisitDateLastACRLastACRDate
12014-12-1836.52014-12-03
12015-04-0912.82015-04-02
12015-05-1411.32015-04-30
22014-01-24412014-01-17
22014-07-2543.22014-07-21
22015-01-2343.22014-07-21

Thank you kindly for any help.

1 Solution

Accepted Solutions
sunny_talwar

May be this:

Visit:

Load * Inline [

Patient, VisitDate

1,2014-12-18

1,2015-04-09

1,2015-05-14

2,2014-01-24

2,2014-07-25

2,2015-01-23

];

ACR:

Load * Inline [

Patient, ACRDate, ACR

1,2014-08-12,24.1

1,2014-12-03,36.5

1,2015-04-02,12.8

1,2015-04-30,11.3

2,2014-01-17,41

2,2014-07-21,43.2

2,2016-01-21,34.4

];

Left Join (Visit)

LOAD Patient,

  Date(ACRDate + IterNo() - 1) as VisitDate,

  ACR as LastACR,

  ACRDate as LastACRDate

While ACRDate + IterNo() - 1 <= EndDate;

LOAD *,

  Date(If(Patient = Previous(Patient), Previous(ACRDate) - 1, Today())) as EndDate

Resident ACR

Order By Patient, ACRDate desc;

DROP Table ACR;

Capture.PNG

View solution in original post

8 Replies
sunny_talwar

May be this:

Visit:

Load * Inline [

Patient, VisitDate

1,2014-12-18

1,2015-04-09

1,2015-05-14

2,2014-01-24

2,2014-07-25

2,2015-01-23

];

ACR:

Load * Inline [

Patient, ACRDate, ACR

1,2014-08-12,24.1

1,2014-12-03,36.5

1,2015-04-02,12.8

1,2015-04-30,11.3

2,2014-01-17,41

2,2014-07-21,43.2

2,2016-01-21,34.4

];

Left Join (Visit)

LOAD Patient,

  Date(ACRDate + IterNo() - 1) as VisitDate,

  ACR as LastACR,

  ACRDate as LastACRDate

While ACRDate + IterNo() - 1 <= EndDate;

LOAD *,

  Date(If(Patient = Previous(Patient), Previous(ACRDate) - 1, Today())) as EndDate

Resident ACR

Order By Patient, ACRDate desc;

DROP Table ACR;

Capture.PNG

marunio007
Contributor III
Contributor III
Author

That is so clever.

It works!

Thank you very much.

sunny_talwar

Did you mean to mark response as correct?

marunio007
Contributor III
Contributor III
Author

I did. The approval delay played a role here....

Thanks again!

sunny_talwar

It still seems that you have marked your response as correct here

Capture.PNG

vishsaggi
Champion III
Champion III

Marek, You marked your comment as Correct Response? Did you get the resolution already before Sunny helped you?

marunio007
Contributor III
Contributor III
Author

My apologies to the both of you.- mistake corrected (I hope)

I promise improvement in my next thread...

sunny_talwar

Apologize not accepted . Just kidding!! Didn't want to harass, but the idea is that others can benefit when they land on this page. Seeing a thanks as the correct response is not very helpful and that's why I harassed you to mark the correct response.

Best,

Sunny