Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How can I calculate weighted / corrected averages with set analysis / aggr function?

Hi, building on the below post I have tried to create a simplified model in Qlikview to calculate weighted / corrected averages:

http://community.qlik.com/forums/t/35791.aspx

PROBLEM:

How can I achieve graph/table CORRECTED AVG FOR SELECTION (APO=A) in Qlikview as calculated in Excel?

CONTEXT:

The goal I'm after is outlined in the attached Excel. Essentially, instead of calculating "naive" averages such as in table/graph "NORMAL AVG", I want to correct this "naive" average by correcting the average for the customer population of the specific store we are evaluating as calculated in "CORRECTED AVG FOR SELECTION (APO=A)".

The input table contains the fields:

- apo = store

- rel_vrd = customer

- gebj_bucket = age group of customer

- ddd_bucket = turnover group of customer

- atc5 = product code (not relevant for now)

The count that I'm doing is to calculate the number of customer contact interactions that are taking place in the different categories.

How can I achieve graph/table CORRECTED AVG FOR SELECTION (APO=A) in Qlikview as calculated in the Excel?

The primary problem that I have identified is that the vector VECTOR PER GEBJ_BUCKET still contains the dimension bbb_bucket (i.e. it is still functioning as a matrix instead of a vector).

Any help is greatly appreciated!

I couldn't attach the files due to a SERVER error, so I put them on box.net:

http://www.box.net/shared/5igr68p1l0

http://www.box.net/shared/55mlyrnhs9

11 Replies
Not applicable
Author

Hamish,

Sorry it took me a while to answer, but I have just programmed what I wanted in SQL and it works great. Now if I can only get the performance of qlikview that would be amazing.

As to your suggestion, I tried the option you mention (show all values - not sure what you mean by populate missing). The reason why the rows need to be the same is because otherwise I cannot calculate the product of that matrix (actually being a vector repeated on each row) with another matrix. Qlikview always remembers what the original buckets are (and I want qlikview to forget, otherwise I keep loosing values in my matrix ).

The core problem is I want to multiply the sum of a set (i.e. the matrix with all rows being equal) with parts of that same set (the matrix with different values). Even if I use set operators, I cannot get Qlikview to forget the original dimensions. There must be a way to strip out the dimension (or to fill the same result for each value of the dimension). I can't seem to find it though.

Any ideas?

hdonald
Creator
Creator

Hi,

I'm out of ideas on the set analysis / aggregation side but I think the problem for Qlikview may be that there is not a complete matrix to work with.

When you add 'ddd_bucket' and 'gebj_bucket' to a pivot chart there are some combinations not present in the 'in memory' table you've created from your input file.

Perhaps if you were to add in rows for the missing combinations - with no value in rel_vrd - you'd get the result requested ,

e.g. if you've already loaded your input file called, say, 'INPUT'

then repeat a number of join loads to combine each element used with every other element to create a complete matrix.

INPUT_PLUS:

LOAD DISTINCT ddd_bucket as Xddd_bucket

RESIDENT INPUT;

OUTER JOIN

LOAD DISTINCT gebj_bucket as Xgebj_bucket

RESIDENT INPUT;

OUTER JOIN

LOAD DISTINCT apo as Xapo

RESIDENT INPUT;

OUTER JOIN

LOAD atc5 as Xatc5

RESIDENT INPUT;

Then use the following to fill in the rel_vrd values -

LEFT JOIN

LOAD apo AS Xapo,

ddd_bucket AS Xddd_bucket,

gebj_bucket AS Xgebj_bucket,

rel_vrd AS Xrel_vrd,

atc5 AS Xatc5

RESIDENT INPUT;

Now try working with INPUT_PLUS as the in memory table for your pivot, using the code from the previous posts to ignore ddd_bucket and 'TOTAL' by gebj_bucket, you should at least now be working with a complete matrix of dimension combinations (only some of which have rel_vrd values)

Regards,

HD