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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Count Last 4 Week AVG

Hi, i have a question,

I have a data like this:

 

AreaWeekQTY
America15
America210
America320
America430
America540
Japan11
Japan21
Japan32
Japan42
Japan53

I want to create a straight table that count the total qty and also the average for last 4 weeks in each area.

The result i expect is like this:

 

AreaWeekSum(QTY)Avg Last 4 Week
America150 --> zero bcs 0 row above
America2100 --> zero bcs only 1 row above
America3200 --> zero bcs only 2 rows above
America4300 --> zero bcs only 3 rows above
America540(5+10+20+30)/4 --> Total Week1-4 divided by 4
Japan110
Japan210
Japan320
Japan420
Japan53(1+1+2+2)/4 --> Total Week 1-4 divided by 4

Is it possible to make it ?

Really need and appreciate your help

Thanks in advance.

I also attach my sample file and data

8 Replies
Kushal_Chawda

=if(Area<>above(Area),0,rangeavg(above(total Sum(QTY),0,4)))

tamilarasu
Champion
Champion

Lejours,

Try this,

If(Below(Area)<> Area,Sum(Total <Area> {<Week -= {"$(=MAX(Week))"}>}[QTY])/ (Count(Total <Area> Week)-1),0)

Capture.PNG

Kushal_Chawda

What if there is 6 and 7 week also?. I think he is asking for last 4 weeks.

varshavig12
Specialist
Specialist

if(Week>4,rangeavg(above(total avg( QTY ),1, 4 )),0)

varshavig12
Specialist
Specialist

Dimension: Area

                 Week

Expression:

sum(QTY)

if(Week>4,rangeavg(above(total avg( QTY ),1, 4 )),0)

tamilarasu
Champion
Champion

I thought it was a sample data. I guess the OP needs a dynamic expression. Lets wait for the reply.

varshavig12
Specialist
Specialist

if(Week>4,rangeavg(above(total sum( QTY ),1, 4 )),0)

Please use sum, instead of avg.

pho3nix90
Creator II
Creator II

I am not sure if the week number is month weeks, or year weeks. (52 weeks), below should be dynamic and do avg every 5 weeks regardless

Try this:

Script:

Directory;

Data:

LOAD Week,

     QTY,

     Area

FROM

[data avg.xlsx]

(ooxml, embedded labels, table is Sheet1);

Left Join

LOAD

*,

if(Mod(Week,5) = 0,

  Peek('AccumQTY'),

  If( RecNo()=1 or Previous(Mod(Week,5) = 0),QTY

  , QTY+Peek('AccumQTY'))

  ) as AccumQTY ;

LOAD

*

Resident Data

Order By Area, Week;

in chart expression

=Sum(if(Mod(Week,5)=0, AccumQTY)/4)