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

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sumif based on aggr

Hello,

I need to sum the sales of all the weeks in a given period of time, which have sales above the average sales of the weeks within that period. Part of the sales data is daily and part of it is weekly. For example:

item

day

week

sales

A

1

40

50

A

2

40

40

A

41

70

A

42

95

In this case the sales in week 40 are 90, in week 41 are 70 and in week 42 the sales are 95. The average weekly sales for item A is 85. Therefore, the weeks with sales above the weekly average are weeks 40 and 42. I need an expression that will give me:

item (dimension)

sales (expression)

A

185

I know that I first need to aggr based on the “week” field. My problem is to create a condition on the aggr grouping, which will pick up and sum only the weeks that are above the average.

Thanks!

Labels (1)
6 Replies
Not applicable
Author

try something like this

If(Sum(Total <Item,Week> Aggr(Sum(Sales),Item,Week))>Avg(Total<Item>  AGGR(sum( Sales),Item,Week)),  sum(Aggr(Sum(Sales),Item,Week)))

MayilVahanan

Hi

PFA

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Not applicable
Author

Hi Devang, unfortunately this doesn't work...

Not applicable
Author

Hi Mayil, i need to solve this without modifying the script. i need to do this on the expression level.

MK_QSL
MVP
MVP

pls check attachment...

Not applicable
Author

Hi Manish, your solution is very close to what i need. the only problem is that there's more than one value under the "item" dimension, and TOTAL ignores that. for example, if the data is:

item

day

week

sales

A

1

40

50

A

2

40

40

A

41

70

A

42

95

B

3

42

100

B

4

42

100

B

43

250

The result needs to be:

item (dimension)

sales (expression)

A

185

B

250

Thanks!