Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

A chart to show the average of a parent dimension value

Hi,

I'm curious to see if this seemingly easy, but in reality quite of a problem can be solved.

I have a chart showing

  • Store as a dimension
  • this year's item availability as a measure 1 (all items, fact fields as binary fields e.g.1 for available or 0 for unavailable item):
    • Sum(AvailableItems)/Sum(WholeOffering)
  • last year's item availability as a measure 2:
    • Sum({$<Year={$(=max(Year)-1)}>}AvailableItems)/Sum({$<Year={$(=max(Year)-1)}>}WholeOffering)

With this data the chart works fine and the measures are displayed like they should be. But I want to add another bar showing the store area average as a third expression.

Below an example of the Store dimension is shown in a table.  Each Store belongs to an Area, e.g. Store values Madrid, Barcelona, Alicante belong to Spain. Store dimension is linked to the fact table with StoreID.

StoreIDStoreAreaStoresInArea
1BarcelonaSpain3
2MadridSpain3
3AlicanteSpain3
4HelsinkiFinland2
5TurkuFinland2

Now I want to show an Area average. If I select one Store from the dimension, this expression gives me the correct answer in a TextBox:

  • (Sum({$<Area=P(Area), Store=>}AvailableItems)/ sum(StoresInArea)) / (Sum({$<Area=P(Area), Store=>}WholeOffering)/Sum(StoresInArea))

The outcome should look like this:

How do I manage it in Qlikview?

Thank you in advance,

Tiia

1 Solution

Accepted Solutions
sunny_talwar

Try this:

Aggr(Avg(TOTAL <Area> Aggr((Sum({$<Area=P(Area), Store=>}AvailableItems)/ Sum({$<Area=P(Area), Store=>}WholeOffering)) / sum(StoresInArea)*100, Store, Area)), Store, Area)

View solution in original post

7 Replies
sunny_talwar

Try this:

Aggr(Avg(TOTAL <Area> Aggr((Sum({$<Area=P(Area), Store=>}AvailableItems)/ Sum({$<Area=P(Area), Store=>}WholeOffering)) / sum(StoresInArea)*100, Store, Area)), Store, Area)

Not applicable
Author

Hi Sunny T!

I tweaked the expression just a little bit (it seemed that the StoresInArea field wasn't needed anymore when AGGR is used) and now it works perfectly!

A BIG thank you

Aggr(Avg(TOTAL <Area> Aggr((Sum({$<Area=P(Area), Store=>}AvailableItems)/ Sum({$<Area=P(Area), Store=>}WholeOffering))*100, Store, Area)), Store, Area)

effinty2112
Master
Master

Hi Tiia,

               The expressions in this straight table may be what you are looking for.

Store

Sum(AvailableItems)

/Sum( WholeOffering)

Sum({$<Year = {2015}>}AvailableItems)

/Sum({$<Year = {2015}>} WholeOffering)

Aggr(NODISTINCT Sum(AvailableItems),Area)

/Aggr(NODISTINCT Sum( WholeOffering),Area)

0.57777777777778 0.55555555555556  
Frankfurt0.50.60.675
Leipzig0.70.60.675
Munich0.70.60.675
Berlin0.80.60.675
Turku0.60.40.55
Helsinki0.50.40.55
Alicante0.30.40.46666666666667
Barcelona0.40.60.46666666666667
Madrid0.70.80.46666666666667

You can make it into a bar chart and sort by the expression =Area & '|' & Store

It looks like:

Chart.JPG

Good luck!

Andrew

Not applicable
Author

Thank you! I'll have a look at this as well.

sunny_talwar

No problem at all

I am glad I was able to help

Not applicable
Author

Hi Sunny,

I noticed a small flaw in the expression in case a user selects a Store. The expression works fine if no Store is selected (or a certain Area is selected) and all stores wth their averages are displayed nicely in the chart . If a Store is selected, then the average should still show the same area average (ignore the Store selection), but now it shows something entirely different. Where should the " Store = " -set analysis be placed in the Expression? I couldn't figure it out 😕

Thanks in advance!

Aggr(Avg(TOTAL <Area> Aggr((Sum({$<Area=P(Area), Store=>}AvailableItems)/ Sum({$<Area=P(Area), Store=>}WholeOffering))*100, Store, Area)), Store, Area)

sunny_talwar

Try with these two changes:

Aggr(Avg({<Store>}TOTAL <Area> Aggr((Sum({$<Area=P(Area), Store=>}AvailableItems)/ Sum({$<Area=P(Area), Store=>}WholeOffering)) / Sum({<Store>}StoresInArea)*100, Store, Area)), Store, Area)

Capture.PNG