Qlik Community

QlikView Layout & Visualizations

Discussion Board for collaboration on QlikView Layout & Visualizations.

Not applicable

Sum function - even there I have a issue - pls help a dummy

Dear community,

I have some issues that a chart shows me a unexpected result of a sum(x)/sum(y).

Can a bloody rooky ask a to easy question?

QV issue.jpg

I load two tables:

QV - load 1.jpgQV - load 2.jpg

and use

Sum(Sales)/Sum(MarketPotential)

as function to get a gauge chart

QV-Out.jpg


Can you pls help me?

Tags (3)
11 Replies
MVP
MVP

Re: Sum function - even there I have a issue - pls help a dummy

If you load these two tables as it is, it will generate a synthetic key(Region+Country) and in that case, result coming is expected. So it's about key issue.

MVP
MVP

Re: Sum function - even there I have a issue - pls help a dummy

HI,

Try like this

Data:

LOAD

    Trim(Region) AS Region,

    Trim(Country) AS Country,

    MarketPotential

FROM Table1;

LEFT JOIN(Data)

LOAD

    Trim(Region) AS Region,

    Trim(Country) AS Country,

     Sales

FROM Table2;

Now check your formula Sum(Sales)/Sum(MarketPotential).

If not working, then attach your sample file.

Regards,

Jagan.

Not applicable

Re: Sum function - even there I have a issue - pls help a dummy

Dear both, thx so much for the fast reply.

Looks good but not completely correct.

Missed the information in the previous question that 'Sales' consist out of multiple datasets

e.g.

GE     (Product1)      3

GE     (Product2)      7

which are added up. The products can be selected as well. (sorry, In thought I have to modify the formular only).

It delivers me the following:

QV - result.jpg

MVP
MVP

Re: Sum function - even there I have a issue - pls help a dummy

Hi,

Can your explain your requirement bit clearly?  What is your expected output for the selection.

Regards,

Jagan.

Not applicable

Re: Sum function - even there I have a issue - pls help a dummy

Hi,

for EU the expected output is Sales [20] / Potential [200] =10%

With      sales :      [GB ProdA = 5] + [GB ProdB = 5] +  [DE ProdA = 3] + [DE ProdB = 7]

             Potential:     [GB=100] + [DE=100]         

The sales of the product should be added up and then divided by the potential market.

Thx

Torsten

MVP
MVP

Re: Sum function - even there I have a issue - pls help a dummy

Duplicate keys will cause you the issue, to avoid that if you can disregard Product, you can get it like:

Data:
LOAD Region,
     Country,
     MarketPotential
FROM
[QV Example.xlsx]
(ooxml, embedded labels, table is MP);

left Join

LOAD Region,
     Country,
     //Product,
     Sum(Sales) as Sales
FROM
[QV Example.xlsx]
(ooxml, embedded labels, table is Sales) group By Region, Country;

Not applicable

Re: Sum function - even there I have a issue - pls help a dummy

I understand, than I have to reload the data (with other var-names) for some other analysis.

Is there any way I could do this in the chart-script

Such as

Sum(total <Region> Sales) / Sum(total <Region> MarketPotential)

while loading two separate tables again?

MVP
MVP

Re: Sum function - even there I have a issue - pls help a dummy

Hi,

Try this script

Sales:

LOAD Region & '_' & Country AS Key,

  Region,

     Country,

     Product,

     Sales

FROM

[QV Example.xlsx]

(ooxml, embedded labels, table is Sales);

Data:

Left Keep(Sales)

LOAD Region & '_' & Country AS Key,  

     MarketPotential

FROM

[QV Example.xlsx]

(ooxml, embedded labels, table is MP);

Regards,

Jagan.

bwisenosimenkg
Valued Contributor

Re: Sum function - even there I have a issue - pls help a dummy

In your example file the following expression gives you the expected output:

sum(Sales)/sum(aggr(sum({<Product={*}>}DISTINCT MarketPotential),Region,Country))

This might have to be modified to fit your full data-set, but it might help you on the way.

Regards

SKG

Community Browser