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: 
its_rajvir
Creator
Creator

SUM IF Function

Hi Experts,

I am trying to use Sum If statement like this 

sum(if (Field1 = 'Something' and Field 2 = 'Something'),1,0)as NewField

But its showing error

Kindly help me where i am getting wrong.

Looking forward for response.

Thanks & Regards,

Rajvir

 

 

Labels (4)
6 Replies
tresesco
MVP
MVP

What error are you getting? Make sure that you are using group by clause with other dimensions in the load.

Or
MVP
MVP

You've got the first ) in the wrong place....

sum(if (Field1 = 'Something' and Field 2 = 'Something',1,0))as NewField

its_rajvir
Creator
Creator
Author

Hi Tresesco, yes i am using group by clause with other dimensions. I am getting invalid expression error when i am using sum if function. 

its_rajvir
Creator
Creator
Author

Hi  @Or  Thankyou, i tried but still getting invalid expression error.

Or
MVP
MVP

Check that your field names are correct. If they include a space, they should be encased in [ ] or quotes  e.g. [Field 2]. You can only use field names that exist in the underlying data source (so if Field1 is something you're calculating in this load script, you can't use it directly).

Mario_ES
Contributor III
Contributor III

Maybe try to reverse it:

Instead of:

sum(if (Field1 = 'Something' and Field 2 = 'Something'),1,0) as NewField

Do:

if (Field1 = 'Something' and Field 2 = 'Something',sum(1),sum(0)) as NewField