Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Caculation of Total

Hello everyone, I am encountering a calculation problem:

Here is a simplified table:

itemvalueSource
190B
1100A
250B
360C

The calculation rule is as follows:

for an Item that can be found in the source A(<>0), we should take the value from source A, otherwise we take the value from Source B.

If we find values from both source A(<>0) and B(<>0), we still take the value from source A.

The same logic applies where there are more sources.

How can we get the right total by using a formula? In the above example, the total should be 100+50+60=210?

Here's the formula I used but I don't get the right answer.

=if(sum({$<Source={'A'}>}[value])<>0,

sum({$<Source{'A'}>}[value]),

if(sum({$<Source={'B'}>}[value])<>0,

sum({$<Source={'B'}>}[value]),

if(sum({$<Source={'C'}>}[value])<>0,

sum({$<Source={'C'}>}[value])

)))

Thanks for your help!

1 Solution

Accepted Solutions
MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_138154_Pic1.JPG.jpg

hope this helps

regards

Marco

View solution in original post

5 Replies
maxgro
MVP
MVP

expression is

sum(aggr(subfield(Concat(value, '@', Source), '@', 1), item))

1.png

MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_138154_Pic1.JPG.jpg

hope this helps

regards

Marco

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this in script

Data:

LOAD

*,

If(Item <> Previous(Item), 1, 0) AS Flag;

LOAD

Item,

Value,

Source

FROM DataSource

ORDER BY Item, Source;

Now use this expression

=Sum({<Flag={1}>} Value)

Hope this helps you.

Regards,

jagan.

perumal_41
Partner - Specialist II
Partner - Specialist II

Hi

Try this

sum({$<Source={"=Sum([value]))<>0"}>}[value])

Not applicable
Author

Hi Marco,

It's great! However, I think I simplified too much my model here and I still can't figure out what I should do in my real life application, which is even more tricky:

     -If the value is found in A, then we take this value

     -If the values are found in B or C, we take the sum of them

itemvalueSource
190B
1100A
250B
240C
360 C

So the result I would expect in my real life application is:

100+(50+40)+60=250

What would you advise?

Thanks a lot!