Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

aggr on field not in chart

Hi,

I need to average data at one level, then sum those avgs at the next level in a chart. The issue is the interim level is not in the chart.

Here is a sample of the data

StateCityProductCostYearQuantity
CaliforniaSan DiegoA50201321
CaliforniaSan DiegoB40201315
CaliforniaSan DiegoC25201354
CaliforniaSan DiegoA50201444
CaliforniaSan DiegoB40201410
CaliforniaSan DiegoC25201430
CaliforniaLAB40201333
CaliforniaLAD75201340
CaliforniaLAE65201326
CaliforniaLAB40201433
CaliforniaLAD75201440
CaliforniaSan FranA50201344
CaliforniaSan FranF35201316
CaliforniaSan FranA50201427
CaliforniaSan FranF35201433
OhioColumbusB40201312
OhioColumbusD75201417
OhioColumbusF35201433
OhioToledoE65201325
OhioToledoE65201457
OhioClevelandB40201322
OhioClevelandC25201332
OhioClevelandA50201418
OhioClevelandB40201434
OhioClevelandC25201423

The issue is I need to avg the sales by City, then sum those avgs at the State level. The end chart i want is showing Sales by State for current Year and last year (but not have the City dimension in the chart).

So far, my current & prior Year expressions are:

sum({$<Year={$(=ONLY(Year)-1)}>} Cost*Quantity ) / count({$<Year={$(=ONLY(Year)-1)}>} Product )

sum({$<Year={$(=ONLY(Year))}>} Cost*Quantity ) / count({$<Year={$(=ONLY(Year))}>} Product )

but that is just the averaging piece of the puzzle. I need to perform the avg per city, then sum per State (without the City being a chart dimension.

Any help would be appreciated,

R.

1 Solution

Accepted Solutions
SergeyMak
Partner Ambassador
Partner Ambassador

Try this

avg(Aggr(avg(Cost*Quantity),City,Year,State))/avg(Aggr(Count( Product),City,Year,State))

and see an example

Regards,
Sergey

View solution in original post

3 Replies
SergeyMak
Partner Ambassador
Partner Ambassador

Try this

avg(Aggr(avg(Cost*Quantity),City,Year,State))/avg(Aggr(Count( Product),City,Year,State))

and see an example

Regards,
Sergey
chiru_thota
Specialist
Specialist

Are you expecting  Avg value at City level aggregated to State as shown in below example?

Ex    : California = 4529

           Ohio = 5865

I guess it will be easy if you can try that at data model level instead of set analysis by having separate column.

aggr.jpg

Not applicable
Author

Thanks Sergei,

I was able to use your solution. The main issue i was having was that one of the aggr fields isn't in the chart as a dimension, but it seems to work as long as one of the aggr fields is in the chart.

Thanks again,

Richard