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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
dbosboom
Partner - Contributor II
Partner - Contributor II

Stock information based on latest EMPTY message.

 

Hi all,

First of all thanks in advance for helping! This community has been a huge help for me so far without even needing to post something. The time has finally arrived that I have to post something as I have not been able to find the right answer. The following has been keeping me busy for the last 2 days.

A customer wants to see the day-to-day stock information of their products per silo. Meaning that they select a date and they want to see everything that has been added to or used from that silo, previous to that date.

Their system creates a row in the database each time the silo is completely empty, meaning that I only have to calculate the stock from the selected date back in time until the first “Empty” message. Everything before this message is irrelevant.

I’ve tried coming up with a decent illustration of what I mean. See below:

DateTimeWeight(kg)SiloCode
25/02/201604:00+20006008
25/02/201603:45+10006007
24/02/201623:01+10006006
24/02/201614:5106EMPTY
24/02/201614:50-67006005
24/02/201614:42+23006004
24/02/201614:32+34006003
24/02/201613:58-14006002
24/02/201613:42+24006001


Let´s say they have selected the 25th of February and silo 6. They now need only need to see the rows with code 006, 007 and 008.

 

My set analysis looks like this: SUM({<Date = {"<=$(=Max(Date))"}>}Weight)

But this also shows all the rows before the empty message. 

I’ve also tried: =SUM({<Datum = {">=$(=Min({<Code = {'EMPTY'}>} Date)) <=$(=Max(Date))"}>}Weight) to get the minimum date with the code EMPTY but there can be more than 1 when going back in time.

Do you guys have any idea how to find the first EMPTY value prior to the selected date?

Thanks!

1 Solution

Accepted Solutions
sunny_talwar

Try this:

=Sum({<Date = {">=$(=Date(Max({<Date = {'<=$(=Max(Date))'}, Code = {'Leegmelden'}>} Date))) <=$(=Max(Date))"}>}Weight)

View solution in original post

11 Replies
sunny_talwar

Have you tried with Max instead of Min here?

=Sum({<Date = {">=$(=Max({<Code = {'EMPTY'}>} Date)) <=$(=Max(Date))"}>}Weight)

dbosboom
Partner - Contributor II
Partner - Contributor II
Author

I just did and that doesn't work either. Also when I only select the silo and nothing else (when using that expression), it shows the correct value in the table but when selecting a date, it shows all values. Multiple EMPTY messages.

sunny_talwar

I am not sure I completely follow, would you be able to provide a sample where you are seeing this issue? It is difficult to understand multiple Empty when I am only seeing a single EMPTY in your sample.

rubenmarin1

Hi Dennis, maybe you can change the code dimension to a calculated dimension like:

=Aggr(Only({<DateTime={"<=$(Max({<Code={'EMPTY'}, DateTime={""<=$(=Max(DateTime))""}, Date>} DateTime))"}>} Code), Code)

Or use this condition in expression to filter values to show.

tresesco
MVP
MVP

Try expression like:

Only({<Date={'>$(=Date(Max({<Date,Code={EMPTY}>}Date))) <=$(=Date(Max(Date)))'}>}Code)


for weight,


Sum({<Date={'>$(=Date(Max({<Date,Code={EMPTY}>}Date))) <=$(=Date(Max(Date)))'}>}Weight)

dbosboom
Partner - Contributor II
Partner - Contributor II
Author

I've created a sample app with the data as is and translated the field names to English. In the field Code there's a value called Leegmelden, that is the EMPTY message that I'm talking about

tresesco
MVP
MVP

To be more accurate and include the timestamp as well in the analysis, you have to generate a timestamp field in the script, like:

LOAD Date,

    Time,

    [Weight(kg)],

    Silo,

    Code,

    Timestamp(Date+Time) as TimeStamp

FROM

[https://community.qlik.com/thread/241523]

(html, codepage is 1252, embedded labels, table is @1);

And then try expression like:

Sum({<Date,TimeStamp={'>$(=Timestamp(Max({<Date,Code={EMPTY}>}TimeStamp))) <=$(=Timestamp(Max(TimeStamp)))'}>}[Weight(kg)])

Assuming the selection would be in Date field.

Capture.PNG

sunny_talwar

I guess tresesco‌ expression might make sense then:

=Sum({<Date = {">=$(=Date(Max({<Date, Code = {'Leegmelden'}>} Date))) <=$(=Max(Date))"}>}Weight)

dbosboom
Partner - Contributor II
Partner - Contributor II
Author

This works like a charm for the first Empty message and selecting a date after, see FirstEmpty.jpg. But when I select the date before 27-10-20, it shows everything again, see SecondEmpty.jpg. Using the Sample(3).qvw that Sunny T provided.

We're getting there though!