Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to get a conditional sum()?

I have a table that looks like:

CategoryMyFlagAmt
Ay20.00
Ay25.60
Bn30.32
Cn70.00
Cy9.10

I want a measure that computes the sum of the selected records where MyFlag='y'.  E.g. if all five are selected the measure is 20+25.6+9.10.  The expression I am using is Sum({$<MyFlag='y'>}Amt), but it always shows 0 (zero). Any ideas for what I'm doing wrong?  The expression editor doesn't show any syntax errors.

Thanks

1 Solution

Accepted Solutions
oknotsen
Master III
Master III

The correct Set Analysis statement should be this:

sum({$ < MyFlag = {'y'} > } Amt)

Notice the missing curly brackets in your statement .

May you live in interesting times!

View solution in original post

8 Replies
oknotsen
Master III
Master III

The correct Set Analysis statement should be this:

sum({$ < MyFlag = {'y'} > } Amt)

Notice the missing curly brackets in your statement .

May you live in interesting times!
Chanty4u
MVP
MVP

try this

=Sum( {<MyFlag ={'y'} >} Amt)

sunny_talwar

You mentioned about selection, if the sum needs to change based on selection, then I would try this:

=Sum({<Flag *= {'y'}>}Amt)

Not applicable
Author

Thanks, but that didn't make any difference.

Not applicable
Author

I had actually tried that earlier and it didn't work.  When I tried it again didn't work initially.  However, when I X'ed out my existing selections, then it worked. 

sunny_talwar

Well this expression will give you 0 if you select Flag = n, whereas the one provided by others will continue to show you y rows even if you select Flag = n

Not sure if you want this or not

Not applicable
Author

Good to know.  I'm sure it will come in handy.  Thanks.

sunny_talwar