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

Moving Average And Ignoring Some Data

Hi,

I've been using Qlik for the past year but i still have a long way to go.

Currently i want to calculate a moving average, on script, but at the same time i want to ignore some of the data.

My data has the following columns: ID, Store, SALESDATE, PromoFlag, PromoCode and QTD.

From here, I want to get the average sales for the combination of product/store of the previous n-periods (on my example i'm using 56 days or 8 weeks). I want to store the data in the column AvgComQTD/Day.

At the same time, whenever "PromoFlag" is 0 (meaning Promo Code is not null), I don't want to include the sales on the calculation and I want to take the value of the previous day where "PromoFlag" is 1.

IDStoreSALESDATEPromoFlagPromo CodeQTDComQTD(last 56days)ComCountDate(last 56)AvgComQTD/Day
97271065112/01/20161-10,0010,001,0010,00
97271065120/01/20161-30,0040,002,0020,00
97271065128/01/20160PPD0010290,0040,002,0020,00

 

In the end i want to have the following columns on my table: ID, Store, SALESDATE, PromoFlag, PromoCode, QTD and AvgComQTD/Day.

 

Once i have the table loaded I want to make some analysis like:

PromoCodeMin of SALESDATEMax of SALESDATESum of QTDSum of Avg. QTD/DayIncrementalIncremental(%)
PPD001028/01/201628/01/201629020,00270,001350%
PPD003126/02/201626/02/20161200,00120,00 
PPD004222/03/201625/03/2016130130,000,000%
PPD006630/04/201630/04/201614020,00120,00600%

 

Ideally I would like to have the calculation on script, but if this can be achieved with aggr() function I can also give it a try.

Please find attached an excel file with the sample data and the view i want to achieve.

 

Thank you,

Michael

Labels (1)
2 Replies
Channa
Specialist III
Specialist III

i am just trying to put sample

 

IF(Previous(ID)=ID,RangeAVG(Peek(QTD),QTD),QTD) AS QTD;

 

QTD is ur measure, ID is dimension 

 

may be i use this for rangesum in script 

 

you can have multiple condition 

Previous(ID)=ID and peak(store)=store

Channa
Michael_TP
Contributor III
Contributor III
Author

Hi Channa, thank you for help.

After a bit more research I found this post which seems to answer my question:

"A simple solution would be to join on the revenue data for the single month 12 months previously, then cumulatively subtract at the sane time as the cumulative sum. This example will run by itself in a script:"

https://community.qlik.com/t5/QlikView-Scripting/Cumulative-12-months-Sum-on-load-script/m-p/560887