Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Modernize Your QlikView Deployment webinar, Nov. 3rd. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator II
Creator II

Need to add values based on before two dates

Hi friends,

I have date and cost column. all i need is just one more field which consists of total cost for current day + last two days in load script.

Please find the attached screenshot below.

source.PNG

Please let me know in case of any clarifications.

1 Solution

Accepted Solutions
Highlighted
Specialist
Specialist

Please try the below:

load *, rangesum(Cost, peek(Cost, -1), peek(Cost,-2)) as Total;

LOAD * Inline [

Date, Cost

2/2/2018 , 10

2/3/2018 , 20

2/4/2018 , 50

2/5/2018 , 60

2/6/2018 , 70

2/7/2018 , 20

2/8/2018 , 50

2/9/2018 , 60

2/10/2018 , 90

2/11/2018 , 15

2/12/2018 , 20

2/13/2018 , 25

];

View solution in original post

13 Replies
Highlighted
Master
Master

use this expression

=rangesum(sum(Cost),Above(Cost,1),Above(Cost,2))

Highlighted
Specialist II
Specialist II

Hi Kumar,

Use Peek(Total)+Cost AS TOTAL

Highlighted
Master
Master

Capture.JPG

Creator II
Creator II

Thanks. but i just want that in load script.  i want to add more field named total in load script.

Highlighted
Creator II
Creator II

Hi Eduardo,

Total you are referring inside peek function is the column i just want to create.

i want it in load script . so only i can generate charts.

Highlighted
Specialist II
Specialist II

Peek() is a script function

Highlighted
Creator II
Creator II

yes i agree. but i just want to know what is the field "total" you used inside peek function?

and also i need to get the addition of above two rows only.

Highlighted
Specialist II
Specialist II

Ah, ok...Try this

Peek(Cost,1)+Peek(Cost,2) AS TOTAL



Highlighted
Specialist
Specialist

Please try the below:

load *, rangesum(Cost, peek(Cost, -1), peek(Cost,-2)) as Total;

LOAD * Inline [

Date, Cost

2/2/2018 , 10

2/3/2018 , 20

2/4/2018 , 50

2/5/2018 , 60

2/6/2018 , 70

2/7/2018 , 20

2/8/2018 , 50

2/9/2018 , 60

2/10/2018 , 90

2/11/2018 , 15

2/12/2018 , 20

2/13/2018 , 25

];

View solution in original post