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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Time in Status

Hi all,

I have a table with change times and new status change for various products.

Would it be possible to get a straight table calculating the accumulated time a product is in a status?

Example:

Source:

IDProductChangeDateNewStatus
1A20/07/17 13:00:00Start
2B20/07/17 13:00:00Start
3A21/07/17 08:00:00Halt
4C22/07/17 12:00:00Start
5B23/07/17 09:00:00Halt
6A23/07/17 12:00:00Start
7B23/07/17 13:00:00Start
8A24/07/17 08:00:00Stop

Result Straight Table:

ProductStatusTime in Status
AStart39:00:00
AHalt52:00:00
BStart68:00:00
BHalt4:00:00
CStart-

I would appreciate any help here.

1 Solution

Accepted Solutions
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Try this:

_tmp:

LOAD * INLINE [

ID, Product, ChangeDate, NewStatus

1, A, 20/07/17 13:00:00, Start

2, B, 20/07/17 13:00:00, Start

3, A, 21/07/17 08:00:00, Halt

4, C, 22/07/17 12:00:00, Start

5, B, 23/07/17 09:00:00, Halt

6, A, 23/07/17 12:00:00, Start

7, B, 23/07/17 13:00:00, Start

8, A, 24/07/17 08:00:00, Stop

];

StatusDuration:

LOAD

ID, Product, ChangeDate, NewStatus,

if(Product = peek('Product', -1),

    peek(ChangeDate) - ChangeDate) as Duration

RESIDENT _tmp

ORDER BY Product, ChangeDate desc;

Drop Table _tmp;

View solution in original post

5 Replies
Anil_Babu_Samineni

Why Product - A and Status - Start ?? Why 39 hours rather 25 hours

Capture.PNG

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

Product A is 2x in Status Start

ID1 to ID3 19:00:00

ID6 to ID8 20:00:00

marcus_malinow
Partner - Specialist III
Partner - Specialist III

Try this:

_tmp:

LOAD * INLINE [

ID, Product, ChangeDate, NewStatus

1, A, 20/07/17 13:00:00, Start

2, B, 20/07/17 13:00:00, Start

3, A, 21/07/17 08:00:00, Halt

4, C, 22/07/17 12:00:00, Start

5, B, 23/07/17 09:00:00, Halt

6, A, 23/07/17 12:00:00, Start

7, B, 23/07/17 13:00:00, Start

8, A, 24/07/17 08:00:00, Stop

];

StatusDuration:

LOAD

ID, Product, ChangeDate, NewStatus,

if(Product = peek('Product', -1),

    peek(ChangeDate) - ChangeDate) as Duration

RESIDENT _tmp

ORDER BY Product, ChangeDate desc;

Drop Table _tmp;

Anil_Babu_Samineni

Are you expecting front end with out touch the script?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

That seem to work.

Too bad this has to be calculated during the load sequence of the data and can't be calculated in a way by Qlikview.