Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
mario-sarkis
Creator II
Creator II

Comparing to fields in Set Analysis

Hey All,

Here is my question I need to calculate the sum of Amount if the "From ID" is Deferent Then "To ID" Example :

From ID      To ID       Amount

1                  1            $1,000

1                   2           $3,000

1                   5           $4,000

Aggregation  OUT:

From ID            Total Amount

1                           $7,000

Hope you can help,

Thank you.

8 Replies
fvelascog72
Partner - Specialist
Partner - Specialist

Hi,

This can help:

Sum(If([From ID] <> [To ID], Amount))

Saludos.

vinieme12
Champion III
Champion III

Two ways to do this

Option1:

use expression

          = SUM(if( FromID <> ToID , Amount))

Option2:

Create key in script that identifies each row separately/uniquely

LOAD * , Rowno() as RowKEY INLINE [

From ID    ,To ID ,      Amount

1                ,  1    ,        $1,000

1                 ,  2  ,         $3,000

1                  , 5 ,          $4,000

];

Then in chart use Expression

=Sum( {< RowKEY = {"=FromID<>ToID"} >} Amount)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
sebastianlettner
Partner - Creator
Partner - Creator

Hallo,

i would create a flag in the script using the folluwing code

LOAD

     [From ID],

     [To ID],

     Amount,

     If([From ID] <> [To ID], 1, 0) as Flag

If you have this Flag field you can use this expression

Sum(Amount * Flag)

Regards

Sebastian

andrei_delta
Partner - Creator III
Partner - Creator III

Hello,

What you are looking for is this: sum({<[To ID]-=P([From ID])>} Amount)

The result:

Capture.PNG

Hope it hels,

Andrei

effinty2112
Master
Master

Hi Andrei,

Try your expression with this data:

LOAD * INLINE [

    From ID,      To ID,      Amount

    1,                  1,            $1000

    1,                  2,          $3000

    2,                  3,          $4000

];

The correct answer should be $7,000 but your expression, sum({<[To ID]-=P([From ID])>} Amount), will return $4,000. The second line should be included in the sum because for this record [From ID] <> [To ID]. Your expression excludes all Amounts that have a [To ID] value that appears as a value for [From ID] for any record.


Kind regards


Andrew

effinty2112
Master
Master

Hi Mario,

You have lots of choices, here's one more:

=sum({$<Amount = {"= [From ID] <> [To ID]"}>}Amount)

Regards

Andrew

vinieme12
Champion III
Champion III

this will fail when the Amount value is similar to another row which actually satisfies the condition

for example try with

LOAD * INLINE [

    From ID,      To ID,      Amount

    1,                  1,            $3000

    1,                  2,          $3000

    2,                  3,          $4000

];

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
effinty2112
Master
Master

Hi Vineeth,

You're right. I really need a unique ID. Sloppy of me to think Amount could be used.

Thanks

Andrew