Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
poortman
Contributor II
Contributor II

Utilization per day per hour

Hi all,

 

I need some help with scripting. We've got patiënts in our nursing wards, with a StartDateTime  and a EndDateTime ('DD-MM-YYYY hh:mm'), like this:

AdmissionNoStartDateTimeEndDateTime
102-01-2021 09:2703-01-2021 10:51

 

For this AdmissionNo I want to see the utilization per day per hour, like this:

AdmissionNoDateTimeDurationBucket
102-01-2021 09:0031
102-01-2021 10:0060
102-01-2021 11:0060
.... 
103-01-2021 10:0051

 

I already tried something, but this only works for when startdate is the same as the enddate..

Transactie:
Load *,

Iterno() as BucketID,
Hour(StartDateTime  +(iterno()-1)*MakeTime(1)) as Bucket_Hour,
Round((RangeMin(EndDateTime ,Ceil(StartDateTime  +(iterno()-1)*MakeTime(1), MakeTime(1)))
-RangeMax(StartDateTime  ,Floor(StartDateTime  +(iterno()-1)*MakeTime(1), MakeTime(1))))
*60*24) as DurationBucket
WHILE StartDateTime  +(iterno()-1)*MakeTime(1) <= Ceil(EndDateTime ,MakeTime(1));

 

Kind regards,

Niek Poortman

Labels (1)
1 Solution

Accepted Solutions
poortman
Contributor II
Contributor II
Author

Think I solved this one. Maybe it can be done in a easier way, but this seems to work. 

Here's the scripting I used.

Transactie:
Load *,
Date(Floor(StartDateTime),'DD-MM-YYYY') as Date,
Hour(StartDateTime) as Hour;
Load *,
TimeStamp(Timestamp(floor(StartDateTime,1/24),'DD-MM-YYYY hh')+(iterno()-1)*MakeTime(1),'DD-MM-YYYY hh') as DateTime,
Round((RangeMin(EndDateTime,Ceil(StartDateTime+(iterno()-1)*MakeTime(1), MakeTime(1)))
-RangeMax(StartDateTime,Floor(StartDateTime+(iterno()-1)*MakeTime(1), MakeTime(1))))
*60*24) as DurationBucket
While TimeStamp(Timestamp(floor(StartDateTime,1/24),'DD-MM-YYYY hh')+(iterno()-1)*MakeTime(1),'DD-MM-YYYY hh') <= Ceil(EndDateTime,MakeTime(1));
;

 

View solution in original post

1 Reply
poortman
Contributor II
Contributor II
Author

Think I solved this one. Maybe it can be done in a easier way, but this seems to work. 

Here's the scripting I used.

Transactie:
Load *,
Date(Floor(StartDateTime),'DD-MM-YYYY') as Date,
Hour(StartDateTime) as Hour;
Load *,
TimeStamp(Timestamp(floor(StartDateTime,1/24),'DD-MM-YYYY hh')+(iterno()-1)*MakeTime(1),'DD-MM-YYYY hh') as DateTime,
Round((RangeMin(EndDateTime,Ceil(StartDateTime+(iterno()-1)*MakeTime(1), MakeTime(1)))
-RangeMax(StartDateTime,Floor(StartDateTime+(iterno()-1)*MakeTime(1), MakeTime(1))))
*60*24) as DurationBucket
While TimeStamp(Timestamp(floor(StartDateTime,1/24),'DD-MM-YYYY hh')+(iterno()-1)*MakeTime(1),'DD-MM-YYYY hh') <= Ceil(EndDateTime,MakeTime(1));
;