Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
The Peek function doesn't work as expected.
I am creating a cumulative sum of the "qty" column. I am using the self column to sum it with itself within the same "sno". when the "sno" changes, I start afresh.
Please give a fix.
Test:
LOAD
*
FROM [lib://DataFiles/Book (2).xlsx]
(ooxml, embedded labels, table is Sheet1);
Test2:
LOAD
sno as sno1,
qty as qty1,
if(RowNo()=1,qty,
if(sno = peek(sno), qty + peek(Cumulative_qty,-1), qty )) as Cumulative_qty
resident Test;
Please try something like this. Peek(sno) doesn't work because column sno doesn't exists in the output data, but you can use previous.
I would also recommend sorting by sno just in case file doesn't come ordered.
Test:
LOAD
*
FROM [..\..\..\Downloads\Book (2).xlsx]
(ooxml, embedded labels, table is Sheet1);
Test2:
LOAD
sno as sno1,
qty as qty1,
if(sno = previous(sno), qty + peek(Cumulative_qty), qty ) as Cumulative_qty
resident Test
order by sno;
Test:
LOAD
*
FROM [lib://DataFiles/Book (2).xlsx]
(ooxml, embedded labels, table is Sheet1);
Test2:
LOAD
sno as sno1,
qty as qty1,
if(RowNo()=1,qty,
if(sno = peek(sno1), qty + peek(Cumulative_qty,-1), qty )) as Cumulative_qty
resident Test;
I am glad you guys found a solution for this.I see that you have moved from peek() to previous (), but I just want to point out an syntax error that didn't get mentioned in your original post.
If you were to peek a field named sno, then the correct syntax would be Peek('sno'). It takes the string name as a parameter not the field it self.
peek function using in 2 places,which peek is not functioning as expected?
if(RowNo()=1,qty,
if(sno = peek(sno), qty + peek(Cumulative_qty,-1), qty )) as Cumulative_qty
peek(sno)
Please try something like this. Peek(sno) doesn't work because column sno doesn't exists in the output data, but you can use previous.
I would also recommend sorting by sno just in case file doesn't come ordered.
Test:
LOAD
*
FROM [..\..\..\Downloads\Book (2).xlsx]
(ooxml, embedded labels, table is Sheet1);
Test2:
LOAD
sno as sno1,
qty as qty1,
if(sno = previous(sno), qty + peek(Cumulative_qty), qty ) as Cumulative_qty
resident Test
order by sno;
Test:
LOAD
*
FROM [lib://DataFiles/Book (2).xlsx]
(ooxml, embedded labels, table is Sheet1);
Test2:
LOAD
sno as sno1,
qty as qty1,
if(RowNo()=1,qty,
if(sno = peek(sno1), qty + peek(Cumulative_qty,-1), qty )) as Cumulative_qty
resident Test;
I am glad you guys found a solution for this.I see that you have moved from peek() to previous (), but I just want to point out an syntax error that didn't get mentioned in your original post.
If you were to peek a field named sno, then the correct syntax would be Peek('sno'). It takes the string name as a parameter not the field it self.