Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

How do I count the number of days a project is in the same status?

I collect the below data for multiple Clients, Project IDs, and Statuses. I want to be able to count the number of days that each project is in the same status. How do I do this with either a script or set analysis? The below data shows the statuses over time, but I only need to know how many days each project has been in the last status. In the below example calc I subtracted the dates 23-Apr-16 and 15-Apr-16 to get 18 days. I generated the below straight table using the Aggr function in the Expression.

      

ClientProject IDSupplierStatusLoad DayLast Status Days
Client A12345Supplier AWith Customer - Stakeholder23-Apr-1618
Client A12345Supplier AWith Customer - Stakeholder22-Apr-16
Client A12345Supplier AWith Customer - Stakeholder21-Apr-16
Client A12345Supplier AWith Customer - Stakeholder20-Apr-16
Client A12345Supplier AWith Customer - Stakeholder19-Apr-16
Client A12345Supplier AWith Customer - Stakeholder18-Apr-16
Client A12345Supplier AWith Customer - Stakeholder15-Apr-16
Client A12345Supplier AWith Customer - Legal14-Apr-16
Client A12345Supplier AWith Customer - Legal13-Apr-16
Client A12345Supplier AWith Customer - Legal12-Apr-16
Client A12345Supplier AWith Customer - Legal11-Apr-16
Client A12345Supplier AWith Customer - Legal08-Apr-16
Client A12345Supplier AWith Customer - Legal07-Apr-16
Client A12345Supplier AWith Customer - Legal06-Apr-16
Client A12345Supplier AWith Customer - Legal05-Apr-16
Client A12345Supplier AWith Customer - Legal04-Apr-16
Client A12345Supplier AWith Customer - Legal02-Apr-16
Tags (1)
2 Replies
jerem1234
Valued Contributor II

Re: How do I count the number of days a project is in the same status?

Hi Ed!

     Try having a straight table with dimensions:

Client, Project ID, Supplier, Status

And then have an expression like:

Max([Load Day]) - Min([Load Day])

Hope this helps!

vgutkovsky
Honored Contributor II

Re: How do I count the number of days a project is in the same status?

I'm assuming a project can only have 1 status per day?

Unless your data volume is huge, you shouldn't have to take this logic to the script. What are the dimensions of the chart that you want to display this expression in? In the above example, you included Status and Date as dimensions, but I'm assuming that wouldn't be what you'd actually want? Assuming your only dimensions would be Client, Project ID, and Supplier, your expression would look this like:

max(aggr(

     if(Status=firstsortedvalue(total <[Project ID]> Status,-[Load Day]),

          [Load Day]

     )

     ,[Project ID],[Load Day]

))

-

min(aggr(

     if(Status=firstsortedvalue(total <[Project ID]> Status,-[Load Day]),

          [Load Day]

     )

     ,[Project ID],[Load Day]

))

+ 1

Edit: this is also assuming each project can only have one Supplier. If that's not the case, simply add Supplier to both your aggr() dimensions and your firstsortedvalue() subtotal.

Regards,

Vlad

Community Browser