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

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

Previous() Statement Help

I'm attempting to do a peek "running total" based of the previous date in my table of data.  Currently,  I have this listed as the statement in the script as:


IF(DATE = Previous(DATE) , (RangeSum(SUM(SOLDPERDAY), Peek('RunningTotal')))) as     RunningTotal

The issue I am having, is that it is completely ignoring the if portion and just summing all (see below):

    

DateTimeSOLDPERDAYRunningTotal
4/19/2013 0:0099%3721649
4/19/2013 0:00100%19521844
4/22/2013 0:001%221846
4/22/2013 0:002%421850
4/22/2013 0:003%-221848
4/22/2013 0:005%421852
4/22/2013 0:006%621858
4/22/2013 0:008%-221856

What i want to see is this:

DateTimeSOLDPERDAYRunningTotal
4/19/2013 0:0099%3721649
4/19/2013 0:00100%19521844
4/22/2013 0:001%22
4/22/2013 0:002%46
4/22/2013 0:003%-24
4/22/2013 0:005%48
4/22/2013 0:006%614
4/22/2013 0:008%-212

Any help would be greatly appreciated

9 Replies
aarkay29
Specialist
Specialist

may be this

IF(Date = Previous(Date) , (RangeSum(SOLDPERDAY, Peek('RunningTotal'))),SOLDPERDAY) as    RunningTotal

swuehl
MVP
MVP

How does your complete LOAD statement look like?

Are you using a GROUP BY clause ( I noticed a Sum() aggregation function)?

You may also consider using Peek() instead of Previous()

IF(DATE = Peek(DATE) , (RangeSum(SUM(SOLDPERDAY), Peek('RunningTotal'))),SUM(SOLDPERDAY) ) as     RunningTotal

Anonymous
Not applicable
Author

Yes, there is a group by:

LOAD

IF(DATE= Previous(DATE), (RangeSum(SUM(SOLDPERDAY), Peek('RunningTotal'))))) as RunningTotal,

  NAME,

  DATE,

  time,

  SUM(SOLDPERDAY) AS perDayCOUNT

RESIDENT RECONFIGURED_TICKETING3

  Group By time, DATE, NAME;

swuehl
MVP
MVP

Not sure if the previous() will work correctly / as expected here.

Maybe separate the group by load from the running total, or try with a sorted input table and Peek() [though I am not sure if this will work correctly, either]:

LOAD

IF(DATE= Peek(DATE), (RangeSum(SUM(SOLDPERDAY), Peek('RunningTotal')))), SUM(SOLDPERDAY) as RunningTotal,

  NAME,

  DATE,

  time,

  SUM(SOLDPERDAY) AS perDayCOUNT

   

RESIDENT RECONFIGURED_TICKETING3

  Group By time, DATE, NAME

Order BY NAME, DATE, time;

aarkay29
Specialist
Specialist

LOAD *,

IF(Date = Previous(Date) , (RangeSum(perDayCOUNT, Peek('RunningTotal'))),perDayCOUNT) as    RunningTotal;

Load  

  NAME,

  DATE,

  time,

  SUM(SOLDPERDAY) AS perDayCOUNT

RESIDENT

     RECONFIGURED_TICKETING3

  Group By

      time, DATE, NAME;

Anonymous
Not applicable
Author

If i use peek, it says the memory allocated is exceeded, and i'm not sure how to break it in to two, as it continues to throw an error. any thoughts of how to break it in to two?

swuehl
MVP
MVP

Something like

TMP:

LOAD

  NAME,

  DATE,

  time,

  SUM(SOLDPERDAY) AS perDayCOUNT

   RESIDENT RECONFIGURED_TICKETING3

  Group By time, DATE, NAME;

RESULT:

LOAD

     IF(DATE= previous(DATE), RangeSum(perDayCount, Peek('RunningTotal') ), perDayCount) as RunningTotal,

  NAME,

DATE,

time,

perDayCount

RESIDENT TMP

ORDER BY NAME, DATE, time; // double check if these DATE breaks are what you need


DROP TABLE TMP;

Anonymous
Not applicable
Author

Its still ignoring the previous date

swuehl
MVP
MVP

Ok, to clarify your issue, please upload some sample data, best as INLINE table in a QVW script.