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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Ciara
Creator
Creator

Load rows based on max date time

I have a sql table that looks like below.

ProcedureIDScheduleDateCharge
10302019-01-11860.46
10302019-12-31860.46
10302020-01-01887.05
1141 2018-01-014007.16
1141 2019-12-314176.26
1141 2020-01-014305.31
14192019-01-117657.88
14192020-01-017658.10

 

I'm trying to extract the data for Charge based on the Max(ScheduleDate) of each ProcedureID so what I save in my qvd file looks like below.

ProcedureIDScheduleDateCharge
10302020-01-01887.05
1141 2020-01-014305.31
14192020-01-017658.10

 

Any help would be appreciated.

Thanks

Ciara

 

1 Solution

Accepted Solutions
Taoufiq_Zarra

One solution in load :

Input:

LOAD * INLINE [
    ProcedureID, ScheduleDate, Charge
    1030, 2019-01-11, 860.46
    1030, 2019-12-31, 860.46
    1030, 2020-01-01, 887.05
    1141 , 2018-01-01, 4007.16
    1141 , 2019-12-31, 4176.26
    1141 , 2020-01-01, 4305.31
    1419, 2019-01-11, 7657.88
    1419, 2020-01-01, 7658.10
];

Final:
noconcatenate


load ProcedureID, Date(Max(ScheduleDate),'YYYY-MM-DD') as ScheduleDate, FirstSortedValue(Charge,-ScheduleDate) as Charge resident Input group by ProcedureID;

drop table Input;

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

3 Replies
tresesco
MVP
MVP

Dim: ProcedureID

Exp1: Date(Max(Date))

Exp2: FirstSortedValue(Charge, -[ScheduleDate])

Taoufiq_Zarra

One solution in load :

Input:

LOAD * INLINE [
    ProcedureID, ScheduleDate, Charge
    1030, 2019-01-11, 860.46
    1030, 2019-12-31, 860.46
    1030, 2020-01-01, 887.05
    1141 , 2018-01-01, 4007.16
    1141 , 2019-12-31, 4176.26
    1141 , 2020-01-01, 4305.31
    1419, 2019-01-11, 7657.88
    1419, 2020-01-01, 7658.10
];

Final:
noconcatenate


load ProcedureID, Date(Max(ScheduleDate),'YYYY-MM-DD') as ScheduleDate, FirstSortedValue(Charge,-ScheduleDate) as Charge resident Input group by ProcedureID;

drop table Input;

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Ciara
Creator
Creator
Author

Thank you SO much Taoufiq!  The FirstSortedValue was where I was getting stuck!

This worked beautifully.  Thanks for such a quick response also.

Ciara