9 Replies Latest reply: Nov 10, 2014 10:20 AM by Sergey Makushinsky

# 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

Mor

• ###### Re: compare day to day before in a straight table

Provide some sample data....

• ###### Re: compare day to day before in a straight table

so can see some sample data in the table

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

• ###### Re: compare day to day before in a straight table

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

• ###### Re: Re: compare day to day before in a straight table

here is a sample data

many thanks!

• ###### Re: compare day to day before in a straight table

Hi

Solution here

Time_Filters:

Peek('Date') AS [Date-1],
Peek('Cost') AS [Cost-1];
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

• ###### Re: compare day to day before in a straight table

To be more precise

Time_Filters:

IF(isNull(Peek('Date')), Date(Num(Date)-1), Peek('Date')) AS [Date-1],
IF(isNull( Peek('Cost')),0,Peek('Cost')) AS [Cost-1];
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
];

• ###### Re: Re: compare day to day before in a straight table

it workes great!!

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

• ###### Re: compare day to day before in a straight table

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

• ###### Re: compare day to day before in a straight table

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;

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

Regards

Anand