Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
On Demand Webinar: See Why Thousands of QlikView Users Have Switched to Qlik Sense. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

compare day to day before in a straight table

Hey all!

i am trying to create an expression that will show me the sum of a field but in the previus day

DateDate -1sum cost of Datesum cost of Date -1
2.111.112010
3.112.113020
4.113.114030
5.114.115040

i want to develop  the [sum cost of Date -1] expression in this table but without using the Above() \ Below() Functions

please help!!

Mor

9 Replies
MK_QSL
MVP
MVP

Provide some sample data....

Not applicable

so can see some sample data in the table

my table has 2 fields: date (dimension) and cost (measure)

SergeyMak
Partner
Partner

Hi

Move calculations to the load script and you will achieve the result.

If you'd like a solution, please share a sample of your data.

Regards,

Sergey

Regards,
Sergey
Not applicable

here is a sample data

many thanks!

SergeyMak
Partner
Partner

Hi

Solution here

Time_Filters:

LOAD *,
Peek('Date') AS [Date-1],
Peek('Cost') AS [Cost-1];
LOAD * INLINE [Date,Cost
01/11/2014,10,
02/11/2014,20,
03/11/2014,30,
04/11/2014,40,
05/11/2014,50,
06/11/2014,60,
07/11/2014,70
];


Regards,

Sergey

Regards,
Sergey
SergeyMak
Partner
Partner

To be more precise

Time_Filters:

LOAD *,
IF(isNull(Peek('Date')), Date(Num(Date)-1), Peek('Date')) AS [Date-1],
IF(isNull( Peek('Cost')),0,Peek('Cost')) AS [Cost-1];
LOAD * INLINE [Date,Cost
01/11/2014,10,
02/11/2014,20,
03/11/2014,30,
04/11/2014,40,
05/11/2014,50,
06/11/2014,60,
07/11/2014,70
];


Regards,
Sergey
its_anandrjs

Hi,

Try this way i am updated the Lubranski code for previous Date

SET DateFormat='DD/MM/YYYY';

TableName:

LOAD *,if(IsNull(Peek('Date')),Date( Date - 1 ), Peek('Date')) AS PrevDate,

            if(IsNull(Peek('Cost')),0, Peek('Cost')) AS PrevCost;

LOAD Date#(Date,'DD/MM/YYYY') AS Date,Cost;

LOAD * INLINE [

Date,Cost

01/11/2014,10,

02/11/2014,20,

03/11/2014,30,

04/11/2014,40,

05/11/2014,50,

06/11/2014,60,

07/11/2014,70

];

And you get the table data as

PrevRec.png

Regards

Anand

Not applicable

it workes great!!

but can you please explain me how is it working???

SergeyMak
Partner
Partner

Hi,

Peek() function get the value from the previous row.

IsNull test is needed because Peek() returns Null() for the first row, but it's better to put 0.

You can find more information here Peek() vs Previous() – When to Use Each

Regards,

Sergey

Regards,
Sergey