Qlik Community

Ask a Question

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Announcements
Talk to Experts Tuesday, January 26th at 10AM EST: Qlik Sense. REGISTER NOW
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
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)

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!

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
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

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???

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