Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Ascalon
Contributor II
Contributor II

Measure to convert Timestamps to Dynamic Buckets

Hi all,

I have a production process where unique products (ProductID) move through a series of six stages (StageID) during the course of a single day.

When a ProductID moves to a new stage, a timestamp is generated - e.g.

TimestampProductIDStageID
06:45:2211
06:46:1221
06:52:3312
06:52:3331
07:04:2422
07:06:1413
07:06:1432
07:12:1223
.........

 

I am trying to create a measure that counts all ProductIDs by current StageID when a given timestamp is selected.

My current measure is:

 

Count( Distinct {<Timestamp={"<=$(=Max(Timestamp))"}>} ProductID)

 

It gets me halfway there - it counts all unique ProductIDs up until the point in time selected. But it doesn't provide their current StageID buckets. This is where I get stuck.

The key problem is that I need the MAX(StageID) to evaluate severally within the set (i.e. for each ProductID, for only the records on/before the timestamp) before aggregating the count. Most techniques I have tried effectively apply the MAX to the whole set (thus only counting the products in the most-advanced stage bucket).

Any guidance would be much appreciated.

Apologies for not posting a sample file, the data is commercially sensitive.

1 Solution

Accepted Solutions
Ascalon
Contributor II
Contributor II
Author

For those interested, the solution I ended up devising was to combine the measure noted above with the following calculated dimension:

 

Aggr(FirstSortedValue({<Timestamp={"<=$(=max(Timestamp))"}>}StageID,-StageID),ProductID)

 

This takes the unique ProductIDs generated and buckets them into the highest StageID appearing for that ProductID before the timestamp.

 

View solution in original post

1 Reply
Ascalon
Contributor II
Contributor II
Author

For those interested, the solution I ended up devising was to combine the measure noted above with the following calculated dimension:

 

Aggr(FirstSortedValue({<Timestamp={"<=$(=max(Timestamp))"}>}StageID,-StageID),ProductID)

 

This takes the unique ProductIDs generated and buckets them into the highest StageID appearing for that ProductID before the timestamp.