Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
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?

11 Replies
tresesco
MVP
MVP

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.

jagan
Luminary Alumni
Luminary Alumni

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
Author

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

jagan
Luminary Alumni
Luminary Alumni

Hi,

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

Regards,

Jagan.

Not applicable
Author

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

tresesco
MVP
MVP

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
Author

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?

jagan
Luminary Alumni
Luminary Alumni

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.

simenkg
Specialist
Specialist

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