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

Set Analysis - Setting a field equal to another field

Is it possible to set a field equal to another field using set analysis AND have it apply that logic over a dimension?

I have a dimension called Severity with values of 0 and 1. So my graph is split into a 0 and a 1; I want to show the number of consumers that are 0 for ADL Bathing and how many are 1 for ADL Bating.

I am trying to write this

Sum(If([ADL Bathing] = Severity, _ConsumerCounter)) using Set analysis

The closest thing I can come up with is

sum({<ADL Bathing]=P([Severity])>} _ConsumerCounter)

I'm only using the P function (which I dont want to) becuse that's the only way I can get the expression to say OK. The P function is actually just gruoping all consumers with either a 0 or a 1.

Anyway to set a field equal to another in set analysis?

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Use pick() instead of the if() statement (which only allows for true / false branching):

=pick( Severity+1,

     sum({<[ADL Bathing] = {0} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {1} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {2} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {3} >} _ConsumerCounter)

)

View solution in original post

6 Replies
swuehl
MVP
MVP

A set expression is evaluated once per chart, not considering your dimension value.

So either stick with your first version sum(if(...)) or try maybe

if( Severity,

     sum({<[ADL Bathing] = {1} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {0} >} _ConsumerCounter)

)

Not applicable
Author

Hi Swuehl. This exprssion is working great. Thank you. The only thing is I am trying to expand this to include th eother values. So my Severity is actually 0 through 3 and when I try this

if( Severity,

     sum({<[ADL Bathing] = {3} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {2} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {1} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {0} >} _ConsumerCounter)

)

It doesn't work. Any idea?

swuehl
MVP
MVP

Use pick() instead of the if() statement (which only allows for true / false branching):

=pick( Severity+1,

     sum({<[ADL Bathing] = {0} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {1} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {2} >} _ConsumerCounter),

     sum({<[ADL Bathing] = {3} >} _ConsumerCounter)

)

Not applicable
Author

This worked perfectly. Thank you so much. Out of curiousity, what does the +1 do?

swuehl
MVP
MVP

Adding 1 to the value of Severity.

So a Severity of 0 will execute the first expression in the list, a Severity of 1 the second, etc.

Not applicable
Author

Is it possible not to repeat the sum so many times?

What would you do when you have more than just 4 possible values?