Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

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
Honored Contributor III

Re: How to get a conditional sum()?

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!
8 Replies
oknotsen
Honored Contributor III

Re: How to get a conditional sum()?

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!
sureshqv
Esteemed Contributor III

Re: How to get a conditional sum()?

try this

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

Re: How to get a conditional sum()?

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

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

Not applicable

Re: How to get a conditional sum()?

Thanks, but that didn't make any difference.

Not applicable

Re: How to get a conditional sum()?

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. 

Re: How to get a conditional sum()?

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

Re: How to get a conditional sum()?

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

Re: How to get a conditional sum()?

Community Browser