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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help with set analysis

Hi all,

I have a data set as shown

ParticipantQuestionAnswer
A1Yes
A2No
B1Yes
B2Yes
C1N/A
C2N/A
D1Yes
D2N/A

A participant get to answer either yes, no or N/a for Questions 1 and 2.

My requirement is to find the percentage of responses who answered yes to question 1 and question 2 among total responses. N/A should not be considered.

Answer = ( count of responses who answered yes to question 1 and question 2) / ( count of responses to question 1 which was yes)

In above example , 3 participants answered yes to question 1 and there was one yes and one no to question 2 ( don't count N/A)

therefore- answer = 50% or (1/2)

Numerator = count({ <Question={1} , Answer={Yes}, Question={2},Answer={Yes}> }   Participant) <-- not working

Denominator= count({<Question={1},Answer={'Yes'},Question={2} ,match(Answer,'Yes','No') > } Participant)  -< not working

Any help on how I need to form set analysis expression for Numerator and denomitator?

1 Solution

Accepted Solutions
sunny_talwar

So the issue is that you need to decide if the independent question is bigger or small question. So for example sticking with your example 1179 and 1168. 1179 is independent and 1168 is kind of dependent as in that only where we have yeses for 1179 we will check 1168. In this case 1179 > 1168 we can use this formula

Sum({<Question = {'1179', '1168'}>}aggr(if(match(concat({<Question = {'1179', '1168'}>}Answer, '', -Question),'YesNo','YesYes'),1), Participant))

Alternatively we can use this also

Sum({<Question = {'1179', '1168'}>}aggr(if(match(concat({<Question = {'1179', '1168'}>}Answer, '', Question),'NoYes','YesYes'),1), Participant))


But when the independent number is smaller the formula will change (so for example 1168 < 1179)


Sum({<Question = {'1179', '1168'}>}aggr(if(match(concat({<Question = {'1179', '1168'}>}Answer, '', Question),'YesNo','YesYes'),1), Participant))


Alternatively we can also use

Sum({<Question = {'1179', '1168'}>}aggr(if(match(concat({<Question = {'1179', '1168'}>}Answer, '', -Question),'NoYes','YesYes'),1), Participant))


The issue is that the way the concat function is working here is driving the results for you. If you know the independent question is bigger or smaller this approach will work, if not then I think you are better off using the script approach where you can flag is accordingly without worrying about the concat order.

HTH

Best,

Sunny



View solution in original post

29 Replies
Not applicable
Author

try this

=Count({<Answer={'Yes'}>} Participants)/Count({<Answer={'Yes','No'}>} Participants)

if you want to test . try Num and Den individually and see what results you get

Not applicable
Author

below will give you in total number of Yes answers as percentage of total yes and no

num(count({<Answer={'Yes'}>}Participant)/count({<Answer={'Yes','No'}>}Participant),'###.##%')

sunny_talwar

I have added flags to the script to make it easy:

Script:

Table:

LOAD *,

  If(Answer = 'Yes', 1, If(Answer = 'No', 0)) as Flag;

LOAD Participant,

    Question,

    Answer

FROM

[https://community.qlik.com/thread/164234]

(html, codepage is 1252, embedded labels, table is @1);

Numerator: =Sum(If(Aggr(Sum(Flag), Participant) = 2, 1, 0))

Denominator: =Sum(If(Aggr(Count(Flag), Participant) = 2, 1, 0))

Attaching the qvw for reference.

Best,

Sunny

Not applicable
Author

This is just an example and there are several questions in real. This particular expression needs to consider only responses for question A and B.

Not applicable
Author

The data model is complex and I do not want to disturb it. Is there a way we can settle this in front end using set analysis expresisons?

Not applicable
Author

Hi,

This is just an example and there are several questions in real. This particular expression needs to consider only responses for question A and B.

sunny_talwar

I am sure there must be a way to do it in the front end (just haven't figured it out yet), but we are not making too many changes here. You are just adding this on top of your one table. I doubt this is going to break anything.

LOAD *,

  If(Answer = 'Yes', 1, If(Answer = 'No', 0)) as Flag;

I will check if I can find an alternative as well.

Best,

Sunny

Not applicable
Author

Thanks Sunny. I have made the changes in the load statement. Can you help me form the expresison using Questions A and B alone? As I mentioned earier to another post, this is just an example and there can be multiple questions. I want to filter based on Questions A and B alone.

maxgro
MVP
MVP

If I understand it should be

sum(aggr(if(concat(Answer, '', Question)='YesYes',1), Participant))

/

sum(aggr(if(match(concat(Answer, '', Question),'YesNo','YesYes'),1), Participant))

1.png