Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a Bar chart with an expression that contains a working if Statement:
Count(DISTINCT if( (Field_X = Field_A and Field_Y = Field_B and COUNTRY = 'USA' and TYPE = 'Val'),ID) )
If all the conditions are true I get back a distinct count of IDs.
I have two questions:
(1) Can this be re-written using Set Expression?
I tried re-writing it to the following statement but I'm not getting the correct results. Most likely the use of identifiers and operands are incorrect:
Count(DISTINCT { <Field_X = Field_A>+$1<Field_Y = Field_B>+$2<COUNTRY = {'USA'}>+$3<TYPE = {'Val'}>>} ID)
Any help is greatly appreciated
(2) Is there a difference - performance-wise between the If condition and the set expression or are both the same?
Thanks
@H-Zey Yes you can definitely write the above if expression in the form of Set analysis. Please see below.
Count(DISTINCT if( (Field_X = Field_A and Field_Y = Field_B and COUNTRY = 'USA' and TYPE = 'Val'),ID) )
Can be replaced by
Count(distinct {<Field_X={'Field_A'},Field_Y={'Field_B'},COUNTRY={'USA'},TYPE={'VAL'}>}ID)
Secondly Set expression are the preferred choice for writing Complex expression that contains if conditions.
If this answers your question, kindly like and accept it as your solution.
@H-Zey Yes you can definitely write the above if expression in the form of Set analysis. Please see below.
Count(DISTINCT if( (Field_X = Field_A and Field_Y = Field_B and COUNTRY = 'USA' and TYPE = 'Val'),ID) )
Can be replaced by
Count(distinct {<Field_X={'Field_A'},Field_Y={'Field_B'},COUNTRY={'USA'},TYPE={'VAL'}>}ID)
Secondly Set expression are the preferred choice for writing Complex expression that contains if conditions.
If this answers your question, kindly like and accept it as your solution.
Hi @sidhiq91 ,
Yes! it did work - thank you. I see that you combined all the field all into one set inside the '< > ' tags.
Is that done to treat it as an And?
Will accept it as the solution
Thanks again
@H-Zey Yes you are right. Between {} it is treated as AND. I would recommend you to study Set Analysis Topic from our Qlik Community which will help you resolve many issues.
Happy Learning!