Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Day start function on time and date field

Hi All;

I have the below formula to calculate my LoadingDuration. The problem is its not retaining the correct calculations.

Table2:

    Load* ,

Interval(if(len([First Pick Departure Date])>=4 and Hour([First Pick Departure Date])>=3 or Hour([First Pick Departure Date])<8,DayStart([First Pick Departure Date],1,1/3 ),[First Pick Departure Date])-if(len([First Pick Arrival Date])>=4 and Hour([First Pick Arrival Date])>=3 or Hour([First Pick Arrival Date])<8 ,DayStart([First Pick Arrival Date],1,1/3),[First Pick Arrival Date])) as LoadingDuration;

Load Timestamp#([First Pick Departure Date], 'DD/MM/YYYY hh:mm') as [First Pick Departure Date],

Timestamp#([First Pick Plan Date Start], 'DD/MM/YYYY hh:mm') as [First Pick Plan Date Start],

Timestamp#([First Pick Plan Date End], 'DD/MM/YYYY hh:mm') as [First Pick Plan Date End],

  [Lean ID],

Timestamp#([First Pick Arrival Date], 'DD/MM/YYYY hh:mm') as [First Pick Arrival Date]

FROM

[$(vDataPath)\DASHBOARD REPORT- Randfontein.xlsx]

(ooxml, embedded labels, table is Sheet1);

The following incorrect values are being retained:

   

First Pick Arrival DateFirst Pick Departure DateLoadingDuration
01/12/2015 09:5701/12/2015 14:450:00:00
01/12/2015 21:3802/12/2015 02:050:00:00
02/12/2015 03:5102/12/2015 07:410:00:00
02/12/2015 07:3002/12/2015 10:2024:00:00
02/12/2015 07:3002/12/2015 10:3024:00:00

What might be the problem?

Regards;

Moses

1 Solution

Accepted Solutions
marcus_sommer

I think your conditions couldn't be correct. I see no reason for a len-check and the Hour-checks should be done per AND or both parts needs to be wrapped in brackets. Here an suggestion how it looked more reasonable (Hours-check is replaced with match() which is shorter in this case):

Load *,

Interval(

    if(match(Hour([First Pick Departure Date]), 3,4,5,6,7),

          DayStart([First Pick Departure Date],1,1/3 ),[First Pick Departure Date]) -

    if(match(Hour([First Pick Arrival Date]), 3,4,5,6,7),

          DayStart([First Pick Arrival Date],1,1/3),[First Pick Arrival Date])) as LoadingDuration;

....

- Marcus

View solution in original post

3 Replies
marcus_sommer

I think your conditions couldn't be correct. I see no reason for a len-check and the Hour-checks should be done per AND or both parts needs to be wrapped in brackets. Here an suggestion how it looked more reasonable (Hours-check is replaced with match() which is shorter in this case):

Load *,

Interval(

    if(match(Hour([First Pick Departure Date]), 3,4,5,6,7),

          DayStart([First Pick Departure Date],1,1/3 ),[First Pick Departure Date]) -

    if(match(Hour([First Pick Arrival Date]), 3,4,5,6,7),

          DayStart([First Pick Arrival Date],1,1/3),[First Pick Arrival Date])) as LoadingDuration;

....

- Marcus

swuehl
MVP
MVP

Would be helpful if you could describe your requirement for LoadingDuration calculation (AKA so we get to know why the calculated LoadingDuration values are 'incorrect').

The if-condition in your LOAD script will always return TRUE, so always the THEN branches (Daystart() functions) will be executed.

This seems incorrect to me (why do we need an if-statement then?), but without knowing your requirements, I can't tell what to change.

The Daystart()-functions seem to work for me, but again, without knowing what you are trying to achieve.

First Pick Arrival Date DaystartFPAD First Pick Departure Date DaystartFPDD LoadingDuration
01/12/2015 09:5702.12.2015 08:00:0001/12/2015 14:4502.12.2015 08:00:000
01/12/2015 21:3802.12.2015 08:00:0002/12/2015 02:0502.12.2015 08:00:000
02/12/2015 03:5102.12.2015 08:00:0002/12/2015 07:4102.12.2015 08:00:000
02/12/2015 07:3002.12.2015 08:00:0002/12/2015 10:2003.12.2015 08:00:001
02/12/2015 07:3002.12.2015 08:00:0002/12/2015 10:3003.12.2015 08:00:001
Not applicable
Author

Thanks Marcus, it worked!