Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
purna
Contributor III
Contributor III

last but one value using peek funtion.

Hello Qlikers,

 

I have a data like this from this i have to find the last but one value  using peek function.

 

please help me to solve this..

 

LOAD

"Date",
Sales,
Category

Date Sales Category
1-Jan-21 261.96 Furniture
2-Jan-21 731.94 Furniture
3-Jan-21 14.62 Office Supplies
4-Jan-21 957.578 Furniture
5-Jan-21 22.368 Office Supplies
6-Jan-21 48.86 Furniture
7-Jan-21 7.28 Office Supplies
8-Jan-21 907.152 Technology
9-Jan-21 18.504 Office Supplies
10-Jan-21 114.9 Office Supplies
11-Jan-21 1706.18 Furniture
12-Jan-21 911.424 Technology
13-Jan-21 15.552 Office Supplies
14-Jan-21 407.976 Office Supplies
15-Jan-21 68.81 Office Supplies
16-Jan-21 2.544 Office Supplies
17-Jan-21 665.88 Office Supplies
18-Jan-21 55.5 Office Supplies
19-Jan-21 8.56 Office Supplies
20-Jan-21 213.48 Technology
21-Jan-21 22.72 Office Supplies
22-Jan-21 19.46 Office Supplies
23-Jan-21 60.34 Office Supplies
24-Jan-21 71.372 Furniture

 

Thanks in advance....

4 Replies
stevejoyce
Specialist II
Specialist II

Last but one?  is that 2nd to last?

the 2nd parameter of peek() function is rowno.  -1 is last (loaded) value, -2 is second to last...

let v2ndLastCategory = peek('Category', -2, 'tablename');

purna
Contributor III
Contributor III
Author

Hello Steve,

Thanks for your quick response but loading the same data as it is as shown above can you write the script briefly 

or any other expression if you got strike.

Last but one means: 23-jan-2021 .

 

I tried with this: Let vMaxdate = Date(peek('maxdate',-2,lastdate));

but no ..

stevejoyce
Specialist II
Specialist II

data:

LOAD

"Date",
Sales,
Category

from source

order by Date asc;

let vMaxDate = peek('Date', -2, 'data');

purna
Contributor III
Contributor III
Author

T1:
LOAD

"Date",
Sales,
Category

FROM [lib://DataFiles/Book1.xlsx]
(ooxml, embedded labels, table is Sheet1);
order Date asc;
let vMaxDate = peek('Date', -2, 'data');

what do you mean by asc;   ....

But throwing an error...