Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi experts,
I have a small requirement, where I have to show current price and previous day price on same row,I Cant use Date-1 to get previous day price, because I won't be having weekend data.
Please see example below
ProdId | Date | Price |
A123 | 6/15/2015 | 100 |
A123 | 6/12/2015 | 99 |
A123 | 6/11/2015 | 101 |
A123 | 6/10/2015 | 102 |
A456 | 6/15/2015 | 105 |
A456 | 6/12/2015 | 104 |
A456 | 6/11/2015 | 103 |
A456 | 6/10/2015 | 100 |
o/p table should be
ProdId | Current Price | Previous Price |
A123 | 100 | 105 |
A456 | 105 | 104 |
Table should be dynamic based on date selection. Please help
you can use peek for this
Price:
load * Inline
[ProdId Date Price
A123 6/15/2015 100
A123 6/12/2015 99
A123 6/11/2015 101
A123 6/10/2015 102
A456 6/15/2015 105
A456 6/12/2015 104
A456 6/11/2015 103
A456 6/10/2015 100]
(delimiter is ' ')
;
load
if(Peek(ProdId) = ProdId, Peek(Price)) as [Previous Price],
*
Resident Price
order by ProdId, Date;
drop table Price;
maybe
FirstSortedValue(Price, -Date, 2)
FirstSortedValue(Price, -Date)
Hi Ramon,
Can you let me know if you can do by set analysis, I can't use peek function, because I have to show lot of other columns in table. Please let me know.
doen't work gives null value
When I tried Massimo's suggestion, I didn't get any NULL values:
i have lot of other dimensions in table..may be thats why its not working
maybe is better you post some data with 2 (or more) dimensions
we're answering to a question but the real one is different