Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problem with se analysis

Good morning to everyone

I have two tables one with sales and one with goods cost.

Every sale is connected with every goods purchase of the year using article code.

For every sale i need to calculate an average cost calculated from date of sell -10 days to date of sell (if there aren't purchase in this period i have to consider the first purchase before the date of sell -10).

datamov-->date of sell
datacos-->date of purchase.

I use this expression:
Avg({$<datacos={">=$(=date(datamov-10)) <=$(=date(datamov))"}>}goods_costs)

but costs are calculated on the entire year.

Thanks in advance for help.

2 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Make sure datacos and datamov are real dates and not strings. Use the date# function if necessary (preferably in the load script). If your dateformat is 'DD/MM/YYYY' you can try:

avg({$<datacos={">=$(=date#(datamov),'DD/MM/YYYY')-10)<=$(=date#(datamov),'DD/MM/YYYY')"}>}goods_costs)


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks Gysbert but datamov and datacos are both real dates.

Now expression work but only if a datamov is selected otherwise value is null.

Avg({$<datacos={">=$(=date(datamov-10)) <=$(=date(datamov))"}>} goods_costs)