Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
mazacini
Creator III
Creator III

split duration into separate hours

Hi

I ha

ve a file showing start and finish times like this

NameStartFinish
John11:0013:10
Frank10:1512:15

I want to split it into separate hours like this:

NameStartFinish
John11:0012:00
John12:0013:00
John13:0013:10
Frank10:1511:00
Frank11:0012:00
Frank12:0012:15

Can anyone help me?

13 Replies
hic
Former Employee
Former Employee

Not sure it's the most beautiful solution, but it will probably work...

Load

   Name,

   Time(RangeMax(Start, Floor(Start,1/24)+(iterno()-1)/24),'hh:mm') as Start,

   Time(RangeMin(Finish, Floor(Start,1/24)+iterno()/24),'hh:mm') as Finish

      While Start+(iterno()-1)/24 <= Finish;

Load

   Name,

   Start,

   If(Finish<Start,Finish+1,Finish) as Finish

   FROM (ooxml, embedded labels, table is Sheet1);

HIC

mazacini
Creator III
Creator III
Author

Hi Henric

Works perfectly.

Can I ask one more question?

I want to add additional fields

     RowNo() as Rec#,

         Date(Date,'dd-MMM-yy') as Date,
    
Dept,
    
FixHrs as TtlHrs,
    
Num(FixRate,'##.00') as Rate,

I inserted these fields after the "Name" field in each of the load statements, but I get "Field Not Found" error message.

Cam you help me on this one?

Thank you

Joe


hic
Former Employee
Former Employee

The second (lower) load is executed first and then the result is piped into the first one. So, the first load works as a filter, or additional transformation of data.

In your case, this means that you need to have the fields you mention is both Load statements, so that they are passed on and are part of the final output. So, you need to repead the field names in both loads or use a * in the upper load:

Load *,

   Time(RangeMax(Start, Floor(Start,1/24)+(iterno()-1)/24),'hh:mm') as NewStart,

   Time(RangeMin(Finish, Floor(Start,1/24)+iterno()/24),'hh:mm') as NewFinish

      While Start+(iterno()-1)/24 <= Finish;

Load

   Name,

   RowNo() as Rec#,

   Date(Date,'dd-MMM-yy') as Date,

   Dept,

   FixHrs as TtlHrs,

   Num(FixRate,'##.00') as Rate,  

   Start,

   If(Finish<Start,Finish+1,Finish) as Finish

   FROM (ooxml, embedded labels, table is Sheet1);

HIC

mazacini
Creator III
Creator III
Author

Hi Henric

Just reviewing this thread, and realised I hadn't acknowledged your post.

It worked great.

Thanks for your help.

Rgds

Joe