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

Calculate previous n date's sale for perticular date in table

i have data like 

date, sales

1/1/2017, 100

1/7/2017,20

1/21/2017,200

1/28/2017,80

........

i have to calculate rollimg month sum , no of month depends on user input. If user select 2 then output will be

date, sales, outputvalue1

1/1/2017, 100, 100

1/7/2017,20   ,120

1/21/2017,200,  220

1/28/2017,80,  280

How to do it in set expression?

 

Thanks in advance

Labels (1)
5 Replies
saminea_ANZ
Creator
Creator


@shwethaa wrote:

i have to calculate rollimg month sum , no of month depends on user input. If user select 2 then output will be


In that, Where is the month data? Can you please supply more realistic values for us.

shwethaa
Contributor III
Contributor III
Author

Not exactly rolling month. We want to show week over week percentage change. If input is 2 .then sum of max date and previous to max date. 

One more sum will be sum of sales for3rd maxdate and 4th max date.

(3rd max date sale+4th max date sale)-(1st max date sale+2nd max date sale)

 

Since there is a date column in table, this expression is taking sales of only corresponding date row. It's not summing up other date

saminea_ANZ
Creator
Creator

If input is 4 then? And are you providing input in box?

Channa
Specialist III
Specialist III



 

before date add month column as Month to table and use expression

RangeSum(Above(Sum(Sales), 0, RowNo()))

Channa
Vegar
MVP
MVP

I think the @Channa approach above idea good:
RangeSum(Above(Sum(Sales), 0, RowNo()))
It is flexible because by making selection in the graph you will be able to reduce to the correct number of periods.

However if you want to specify the number of months in your accumulating expression you would, as @saminea_ANZ is saying, need some kind of user input, a variable (or a island field value).
Assuming you have the variable vNumOfMonths you can do this: RangeSum(Above(Sum(Sales), 0, $(vNumOfMonths)))

BR
Vegar