Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
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.

Labels (1)
1 Solution

Accepted Solutions
jagan
Partner - Champion III
Partner - Champion III

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
Partner - Champion III
Partner - Champion III

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)