Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to have set analysis calculation obey current selection

Say I have an expression like so:

Sum({<[Type]={'A'}>}Cost)

I also have a list box for [Type]. And [Type] has A,B,C, etc. I noticed that even if I select [Type]='B' from the list box, the expression above still calculates. Is it possible to have the expression calculate a zero being that Type=A is not part of current selection?

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

The set expression that you use starts from the current selection, but overrides the selection for field Type by forcibly setting it to value 'A'. By specifying the set expression [Type]={'A'}, you are effectively undoing the selection in field Type and putting a new one in place. All other current selections will remain unchanged.

To accomplish what you want, you can use combination operators like -= or *=. The latter is especally useful as it means (temporarily) assign to the field the intersection of the current selection with whatever I specify between braces. Example:

=Sum({<[Type] *= {'A'}>} Cost)

will throw away all currently selected Type values except for value 'A'. If value 'A' wasn't selected to begin with, it will stay unselected in this expression.

View solution in original post

3 Replies
Chanty4u
MVP
MVP

may be this?

Sum({1<[Type]={'A'}>}Cost)

jwjackso
Specialist III
Specialist III

Try Sum({$<[Type]={'A'}*P([Type])>}Cost)

Peter_Cammaert
Partner - Champion III
Partner - Champion III

The set expression that you use starts from the current selection, but overrides the selection for field Type by forcibly setting it to value 'A'. By specifying the set expression [Type]={'A'}, you are effectively undoing the selection in field Type and putting a new one in place. All other current selections will remain unchanged.

To accomplish what you want, you can use combination operators like -= or *=. The latter is especally useful as it means (temporarily) assign to the field the intersection of the current selection with whatever I specify between braces. Example:

=Sum({<[Type] *= {'A'}>} Cost)

will throw away all currently selected Type values except for value 'A'. If value 'A' wasn't selected to begin with, it will stay unselected in this expression.