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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Duration

Hi All,

I have a data set where I am required to calculate the duration of a product that has been 'Live' in hh:mm:ss

DateProduct

Status

10-08-2015 10:12:10 AMWLive
10-08-2015 05:40:25 PMWLive
10-08-2015 07:28:19 PMWDead
10-08-2015 09:30:00 PMWLive
10-08-2015 11:02:34 PMWLive
11-08-2015 06:00:00 AMDLive
11-08-2015 04:20:55 PMDLive
7 Replies
sunny_talwar

Can you share what your required output needs to look like from the sample you have shared? Also, do you want this to be done in script or front end?

MarcoWedel

Hi,

maybe something like

ProductDuration
W12:50:24
D11:20:55
Not applicable
Author

Hi,

Needs to be done in the backend. The desired output would be like :

ProductDuration (hh:mm:ss)
W09 : 16 : 09
D10 : 20 : 55

Live duration will be counted as the difference between the first Live reading till a Dead reading is encountered. So the output above is the exact fig.

Thanks

MarcoWedel

So you are looking for this?

QlikCommunity_Thread_248451_Pic1.JPG

QlikCommunity_Thread_248451_Pic2.JPG

Clever_Anjos
Employee
Employee

Something like this?

Capturar.PNG

Base:

LOAD

    Timestamp#(Date, 'MM-DD-YYYY hh:mm:ss TT') as Date,

    Product,

    Status

FROM [https://community.qlik.com/thread/248451](html, codepage is 1252, embedded labels, table is @1);

LOAD

      Date,

      If(Product = Peek('Product'),Peek('Date'),null())  as Date2,

      Product,

      Status

Resident Base

Order by  Product, Date DESC;

Drop Table Base;

maxgro
MVP
MVP

Result

1.png

Script: I added some test data


Base: 

LOAD 

    Timestamp(Timestamp#(Date, 'DD-MM-YYYY hh:mm:ss TT')) as Date, 

    Product, 

    Status 

FROM [https://community.qlik.com/thread/248451](html, codepage is 1252, embedded labels, table is @1); 

// -------------- comment this, just for test, start

Concatenate (Base)

load

    Timestamp(Timestamp#(Date, 'DD-MM-YYYY hh:mm:ss TT')) as Date, 

    Product, 

    Status 

inline [

Date, Product, Status 

10-08-2016 10:12:10 AM, W, Live

10-08-2016 05:40:25 PM, W, Live

10-08-2016 07:28:19 PM, W, Dead

10-08-2016 09:30:00 PM, W, Live

10-08-2016 11:02:34 PM, W, Live

11-08-2016 06:00:00 AM, D1, Dead

11-08-2016 04:20:55 PM, D1, Live

12-08-2016 06:00:00 AM, D1, Live

12-08-2016 04:20:55 PM, D1, Live

];

// ------------------ comment this, just for test, end

Base2:

LOAD 

  Date, 

    If(Product = Peek('Product') and (Peek('Status')='Dead' or Peek('StatusNew')='Dead'), 'Dead',

    If(not (Product = Peek('Product')), Status,

    Alt(Peek('StatusNew'), 'Live')

    )) as StatusNew,

    Product, 

    Status

Resident Base 

Order by  Product, Date;

Drop Table Base;

Result:

LOAD

  Product,

  Interval(MaxDate - MinDate) as Duration,

  MinDate, MaxDate

;

LOAD

  Product,

  min(Date) as MinDate,

  max(Date) as MaxDate

Resident Base2

Where StatusNew = 'Live'

Group By Product

;

MarcoWedel

using this script:

tabProdStat:

LOAD * FROM [https://community.qlik.com/thread/248451] (html, codepage is 1252, embedded labels, table is @1);

tabProdDur:

LOAD Product,

     Interval(Min(If(Status='Dead',Date))-Min(If(Status='Live',Date))) as Duration

Resident tabProdStat

Group By Product;

hope this helps

regards

Marco