# Take an answer with more mentions

6 days 11 hours ago #230953 by Mon2016
Hello dear forum,

I tell you that I have a problem that I have not been able to solve, that's why I approach the forum to see if someone has had the same problem.

I have a multiple answer question where I show the possible products or categories that you have bought in the last few months.

Example:

P1. Which of the following categories have you bought in the last few months?

1 Fruits and vegetables
2 Beef, pork and chicken, Fish and Seafood
3 Bakery
4 Deli, Refrigerators and Freezers
5 Groceries
6 Household cleaning products
7 Hygiene and personal care
8 Pharmacy
9 Items and Baby Feeding
10 Wines, Spirits and Beers
11 Pet Products
12 Technology / Electronics
13 Computation
14 Cell Phone
15 Appliances and White Line
16 Household Items
17 toy store
18 Clothing and Footwear

Then in a later question it is asked in which supermarkets you have made purchases of these categories, so I have a list of 18 possible supermarkets where they could have bought these categories and I have separated each category in a variable to better show the list of stores in a radio response to select a store by category

Now the dilemma is that I should ask for the supermarket that was most mentioned in question 2.

Why do you mostly shop at...

So I only need to drag the text of the store that was selected the most in the previous set of questions.

I hope I have been clear in my wording.

I also leave you an example with a test equestrian in case someone has gone through something similar.

Greetings to all and thanks for reading.
##### Attachments:

6 days 2 hours ago - 6 days 1 hour ago #230954 by Joffm
Hi,

So I only need to drag the text of the store that was selected the most in the previous set of questions.

Yes, only.
But first you have to calculate the maximum, see which store(s) are affected, deal with ties, ...

I'd do it like that (only using some equations)

1. What is the maximum of mentions?
Here you may use the functions "max" and "countif", like
equation called "eqMax":
{max(countif("1",P8da01.NAOK,P8da02.NAOK,P8da03.NAOK,P8da04.NAOK,P8da05.NAOK,...),countif("2",P8da01.NAOK,P8da02.NAOK,P8da03.NAOK,P8da04.NAOK,P8da05.NAOK,...),countif("3",...))}

2. Which stores were mentioned with this frequency?
Here I build a string with symbols ("A", "B", "C",...) that represent the stores.
Use the function "join"
equation called "eqStores"
{join(if(countif("1",P8da01.NAOK,P8da02.NAOK,P8da03.NAOK,P8da04.NAOK,P8da05.NAOK,...)==eqMax,"A",""),if(countif("2",P8da01.NAOK,P8da02.NAOK,P8da03.NAOK,P8da04.NAOK,P8da05.NAOK,...)==eqMax,"B",""),if(countif("3",...))}
You may get something like "CKO"
To avoid the double calculation of "countif" you could use an array(text) or a "multiple numerical input" to store the results of each "countif" in first equation "eqCount" and use this in the next two equations.

3. We may get more than one store with the same frequency (as shown above). So we select one at random.
First create a random number from 1 - the length of "eqStores" (the number of stores with the same maximum frequency)
Using functions "rand" and "strlen".
equation called "eqRand"
{if(is_empty(eqRand),rand(1,strlen(eqStores)),eqRand)}

4. Now we grab the character from "eqStores" that is in this position "eqRand".
Using function "substr".
equation called "eqStore"
{substr(eqStores,eqRand-1,1)}

5. Either in your question or - as I show - in a last equation before the select the storename in a simple nested IF.statement.
equation called "eqStoreName"
{if(eqStore=="A","Walmart",if(eqStore=="B","Walmart Express (Superama)",if(eqStore=="C","Bodega Aurrera",if(eqStore=="D","Mi Bodega Aurrera",if(eqStore=="E","Bodega Aurrera Express",if(eqStore=="F",...."")))...))))}

Of course: All these equations are hidden after testing.

6. The your question looks like

#### File Attachment:

File Name: limesurvey...42_J.lss
File Size:93 KB

Joffm

By the way:
How do you imagine to deal with your "Other"?
1. You have to include the Code "-oth-" into the calculation.
2. You do not know which store it is.
Let's explain:
You get a frequency of 13 "Others", which is the maximum.
This might be one single "other" store.
But also there might be 13 different stores inserted, so that each of these "other" stores only was mentioned once.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
##### Attachments:
Last edit: 6 days 1 hour ago by Joffm.

6 days 1 hour ago #230955 by Mon2016
Hi Joffm,

Thank you very much for sharing your knowledge,

I tried to import your example into my version of LS to see if I could understand a bit more about what you mentioned.

But it sends me an error that it is not compatible with my version, I am currently using Version 3.25.10+210128

I'm a bit distracted and forgot to mention the version.

I offer an apology in advance.

Moon

5 days 23 hours ago - 5 days 23 hours ago #230962 by Joffm
Yes this is the consequence if you do not answer the questions at the beginning.

I'm a bit distracted and forgot to mention the version.

You did not forget, you removed these questions

I have no idea why people ignore them.
We do not ask them "just for fun".

I sent a survey created in version 5.x..
Because you can't import a lss of 5.x. into a lower version (like 3.x.)

It will take some time to create it again in version 3.x.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 days 23 hours ago by Joffm.

5 days 19 hours ago #230966 by Joffm
Here a version 3.x. export.

Included are two ways to calculate this (I mentined this before).

You only have to extend the equations "countif(" to your 18 P8da questions and decide which way you prefer.

#### File Attachment:

File Name: limesurvey...2_V3.lss
File Size:95 KB

And don't forget about the "Other" stores.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
##### Attachments:

5 days 17 hours ago #230979 by holch

You did not forget, you removed these questions

But Joffm, he/she put a heart in the subject!

Here a version 3.x. export.

@Joffm: You are just too good for this world.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

5 days 16 hours ago #230982 by Joffm

@Joffm: You are just too good for this world.

I know.

And I saw the heart, but too late.

Volunteers are not paid.
Not because they are worthless, but because they are priceless

4 days 4 hours ago #230984 by Mon2016
Hi Joffm,

Thank you very much, I have imported the survey and adjusted the questions for the 19 categories.

I already did a real test with a full survey and this works great.

I agree with @holch, you are too good.

I really appreciate the help and in future topics I will not discard my version.

Greetings to both.

1 day 2 hours ago #231030
All clear and reasonable thank you ! Good luck to you

19 hours 48 minutes ago - 19 hours 46 minutes ago #231039 by holch
@heliousgeorge: I am watching you...

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Last edit: 19 hours 46 minutes ago by holch.

18 hours 4 minutes ago #231057 by tpartner

@heliousgeorge: I am watching you...

LOL!

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.