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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
josemaria_cabre
Contributor III
Contributor III

Script with max, min and total values

Hi,

Let's imagine we load this data in our script:

LOAD * INLINE [
id, date, hour
a1, 01/01/2024, 8:00
a1, 01/01/2024, 9:00
a1, 01/01/2024, 10:24
a1, 01/01/2024, 11:56
a1, 02/01/2024, 7:34
a1, 02/01/2024, 9:00
a1, 02/01/2024, 10:24
a1, 02/01/2024, 14:55
b1, 02/01/2024, 1:02
b1, 02/01/2024, 3:33
b1, 02/01/2024, 4:44
b1, 02/01/2024, 6:25
];

And we'd like to get a summary resident table with 3 calculated fields on it, for each id and date: min date_hour, max_date_hour and total_time:

id date min_date_hour max_date_hour total_time
a1 01/01/2024 8:00 11:56 3:56
a1 02/01/2024 7:34 14:55 7:21
b1 02/01/2024 1:02 6:25 5:23


Is it possible to calculate these fields directly in the script? How would I acchieve that?

Thanks in advance for your help
Jose

Labels (2)
2 Solutions

Accepted Solutions
VBD
Partner - Creator II
Partner - Creator II

Hello,

You can try this,

TMP_TABLE:
LOAD * INLINE [
id, date, hour
a1, 01/01/2024, 8:00
a1, 01/01/2024, 9:00
a1, 01/01/2024, 10:24
a1, 01/01/2024, 11:56
a1, 02/01/2024, 7:34
a1, 02/01/2024, 9:00
a1, 02/01/2024, 10:24
a1, 02/01/2024, 14:55
b1, 02/01/2024, 1:02
b1, 02/01/2024, 3:33
b1, 02/01/2024, 4:44
b1, 02/01/2024, 6:25
];
 
 
TABLE:
Load
id,
    date,
    time(Max(hour)) as Max_Hour,
    time(Min(hour)) as Min_Hour
Resident TMP_TABLE
group by id,date;
 
Drop table TMP_TABLE ;
exit script;
 
VBD_0-1728560814401.png

 

Regards,
Valentin Billaud
Next Decision

View solution in original post

vuan
Partner - Contributor II
Partner - Contributor II

Hi,

you can try this

LOAD *,
interval(max- min, 'hh:mm') as diff;
LOAD
id
, date,
interval(min(hour), 'hh:mm') as min,
interval(max(hour), 'hh:mm') as max
Group by id, date;
LOAD * INLINE [
id, date, hour
a1, 01/01/2024, 8:00
a1, 01/01/2024, 9:00
a1, 01/01/2024, 10:24
a1, 01/01/2024, 11:56
a1, 02/01/2024, 7:34
a1, 02/01/2024, 9:00
a1, 02/01/2024, 10:24
a1, 02/01/2024, 14:55
b1, 02/01/2024, 1:02
b1, 02/01/2024, 3:33
b1, 02/01/2024, 4:44
b1, 02/01/2024, 6:25
];

 

Kind regards

View solution in original post

3 Replies
VBD
Partner - Creator II
Partner - Creator II

Hello,

You can try this,

TMP_TABLE:
LOAD * INLINE [
id, date, hour
a1, 01/01/2024, 8:00
a1, 01/01/2024, 9:00
a1, 01/01/2024, 10:24
a1, 01/01/2024, 11:56
a1, 02/01/2024, 7:34
a1, 02/01/2024, 9:00
a1, 02/01/2024, 10:24
a1, 02/01/2024, 14:55
b1, 02/01/2024, 1:02
b1, 02/01/2024, 3:33
b1, 02/01/2024, 4:44
b1, 02/01/2024, 6:25
];
 
 
TABLE:
Load
id,
    date,
    time(Max(hour)) as Max_Hour,
    time(Min(hour)) as Min_Hour
Resident TMP_TABLE
group by id,date;
 
Drop table TMP_TABLE ;
exit script;
 
VBD_0-1728560814401.png

 

Regards,
Valentin Billaud
Next Decision
vuan
Partner - Contributor II
Partner - Contributor II

Hi,

you can try this

LOAD *,
interval(max- min, 'hh:mm') as diff;
LOAD
id
, date,
interval(min(hour), 'hh:mm') as min,
interval(max(hour), 'hh:mm') as max
Group by id, date;
LOAD * INLINE [
id, date, hour
a1, 01/01/2024, 8:00
a1, 01/01/2024, 9:00
a1, 01/01/2024, 10:24
a1, 01/01/2024, 11:56
a1, 02/01/2024, 7:34
a1, 02/01/2024, 9:00
a1, 02/01/2024, 10:24
a1, 02/01/2024, 14:55
b1, 02/01/2024, 1:02
b1, 02/01/2024, 3:33
b1, 02/01/2024, 4:44
b1, 02/01/2024, 6:25
];

 

Kind regards

josemaria_cabre
Contributor III
Contributor III
Author

Both solutions worked great, 

thank you @vuan @VBD !!