Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Shivam22
Contributor III
Contributor III

Set Analysis with Or condition

Hi All,

I have a data set like below and i need create a textbox to count distinct ID where any of values from test1 to test4 is 1 and other textbox showing count with any of values from test1 to test4 is 0, without counting them twice.

For example - Count(any of values from test1 to test4 is 1) = 5

Count(any of values from test1 to test4 is 0) = 2

 

ID test1 test2 test2 test4
AAA 1 0 1 0
BBB 1 1 1 1
CCC 1 0 1 0
DDD 0 1 0 1
EEE 1 1 1 1
FFF 0 0 0 0
GGG 0 0 0 0

 

Can anyone pls help me understand how to achieve this?

 

Thanks in Advance

Labels (4)
1 Solution

Accepted Solutions
Chanty4u
MVP
MVP

Try this for any 1

=Count(DISTINCT {<ID = {"=Sum(test1+test2+test3+test4) > 0"}>} ID)

Try this for any 0

=Count(DISTINCT {<ID = {"=Sum(test1+test2+test3+test4) = 0"}>} ID)

 

 

Or you can try this way

=Count(DISTINCT If(test1 = 1 or test2 = 1 or test3 = 1 or test4 = 1, ID))

 

For all 0

=Count(DISTINCT If(test1 = 0 and test2 = 0 and test3 = 0 and test4 = 0, ID))

 

View solution in original post

3 Replies
Or
MVP
MVP

This would be a union, seemingly. 

{< test1 = {1} + test2 = {1} + test3 = {1} + test4 = {1} >}

https://help.qlik.com/en-US/sense/May2025/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/SetAnalysi...

marksouzacosta
MVP
MVP

Hi @Shivam22 ,

You can also change your Load Script to facilitate the chart measure:

TestData:
Load 
    ID,
    test1,
    test2,
    test3,
    test4,
    If(RangeSum(test1,test2,test3,test4) = 0,0,1) AS CountFlag
Inline [
ID, test1, test2, test3, test4
AAA, 1, 0, 1, 0
BBB, 1, 1, 1, 1
CCC, 1, 0, 1, 0
DDD, 0, 1, 0, 1
EEE, 1, 1, 1, 1
FFF, 0, 0, 0, 0
GGG, 0, 0, 0, 0
];

 

The Measures will be like:

marksouzacosta_0-1761137652803.png

 

Regards,

Mark Costa

Read more at Data Voyagers - datavoyagers.net
Follow me on my LinkedIn | Know IPC Global at ipc-global.com

Chanty4u
MVP
MVP

Try this for any 1

=Count(DISTINCT {<ID = {"=Sum(test1+test2+test3+test4) > 0"}>} ID)

Try this for any 0

=Count(DISTINCT {<ID = {"=Sum(test1+test2+test3+test4) = 0"}>} ID)

 

 

Or you can try this way

=Count(DISTINCT If(test1 = 1 or test2 = 1 or test3 = 1 or test4 = 1, ID))

 

For all 0

=Count(DISTINCT If(test1 = 0 and test2 = 0 and test3 = 0 and test4 = 0, ID))