Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hey all!
i am trying to create an expression that will show me the sum of a field but in the previus day
Date | Date -1 | sum cost of Date | sum cost of Date -1 |
---|---|---|---|
2.11 | 1.11 | 20 | 10 |
3.11 | 2.11 | 30 | 20 |
4.11 | 3.11 | 40 | 30 |
5.11 | 4.11 | 50 | 40 |
i want to develop the [sum cost of Date -1] expression in this table but without using the Above() \ Below() Functions
please help!!
Mor
Provide some sample data....
so can see some sample data in the table
my table has 2 fields: date (dimension) and cost (measure)
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
here is a sample data
many thanks!
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
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
];
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
Regards
Anand
it workes great!!
but can you please explain me how is it working???
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