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 if

CCYAmount
INR-200
INR-250
EUR0
USD400
USD-300
USD-150

Total AmountTotal Amount in USD
-500-50

I want to use sum if but my logic seems to be not working - can you help?

My script:

LOAD

          sum(Amount) as Total,

          if(CCY = 'USD', sum(Amount)) as TotalUSD

Resident Table;

The if condition does not return any value.

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

DataTemp:

LOAD

     *,

          Amount

          if(CCY = 'USD', Amount, 0) as TotalUSD

Resident Table;

Data:

LOAD
     Sum(Amount) AS Amount,

     Sum(TotalUSD) AS TotalUSD

RESIDENT DataTemp;

DROP TABLE DataTemp;

Hope this helps you.

Regards,

Jagan.

View solution in original post

5 Replies
Not applicable
Author

Try

Sum( if(CCY = 'USD', Amount)) as TotalUSD

Not applicable
Author

Still does not work -> getting no output for TotalUSD

narender123
Specialist
Specialist

HI ,

use this

if(CCY='USD',Amount) as TotalUSD

As you are using aggrgation function the use group by too.

like.

load

a,

b,

sum(Amount) as Total,

if(CCY='USD',Amount) as TotalUSD

from tableabc group by a,b;

Thanks.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

DataTemp:

LOAD

     *,

          Amount

          if(CCY = 'USD', Amount, 0) as TotalUSD

Resident Table;

Data:

LOAD
     Sum(Amount) AS Amount,

     Sum(TotalUSD) AS TotalUSD

RESIDENT DataTemp;

DROP TABLE DataTemp;

Hope this helps you.

Regards,

Jagan.

omyahamburg
Creator II
Creator II

A straight table with no Dim and these expressions will also do it:

=sum(Amount)

=sum({<CCY={'USD'}>}Amount)