Randomly picking from a list of brands but excluding certain combinations | XM Community
Skip to main content

I am creating a monthly survey that has a brand list that that contains a minimum of 1 brand to a max of 10. The brands a respondent will see depends on a whether they shopped there in the past (Q1).  In this example, pretend that the respondent shopped at Brands A, B, C, D and E.

I have a loop and merge where I present a max of 3 brands to the respondent. The only exception would be is that the respondent could not see both Brands A and C. We are allowing all other combinations as long as Brands A and C are not together. 

Is this possible?

 

Keep in mind that the brand list changes every month and that the brands that cannot be together are also changing.

 

Thanks in advance.   

 

hi ​@rarcega, this is possible, but it requires a bit of workaround logic, since Qualtrics’ Loop & Merge does not natively support exclusions between loop items.

Approach: Use Embedded Data and Display Logic
    1.    Create an Embedded Data field in the Survey Flow to store a randomly selected combination of brands (excluding the restricted pair, e.g., A & C).
    2.    Do the randomization via JavaScript in a question placed early in the survey (or as a custom Web Service if you’re okay with server-side logic). This script would:
    • Take the respondent’s eligible brands (from Q1),
    •    Randomly select a subset of 3 brands while excluding combinations like A & C,
    •    Write those 3 selected brands into embedded data fields: Brand1, Brand2, Brand3.
    3.    In the Loop & Merge block, don’t use the brand list directly.
    •    Instead, loop over three positions (Position1, Position2, Position3) and inside each loop, pipe in the corresponding Brand1, Brand2, Brand3.
    4.    This ensures full control of what brands are being shown, and lets you dynamically exclude combinations like A & C.

Let me know if it works.
-- Rochak


I’m a little unclear about step #1. How does this prevent the restricted pair (A and C) from getting selected together? 


Step #1 doesn’t directly prevent the restricted pair (like A & C) — that part happens in Step #2. 

Step #1 is simply about setting up a place to store the final brand choices. You’ll create three Embedded Data fields in your Survey Flow — let’s say:
    •    Brand1
    •    Brand2
    •    Brand3

These will eventually hold the three randomly selected brands, excluding combinations like A & C. Think of these fields as placeholders for the filtered, valid selection.

 

In Step #2, the JavaScript will:
    •    Pull in all eligible brands from Q1
    •    Randomly generate combinations of 3 brands
    •    Skip over any set that contains restricted pairs (like A & C)
    •    Once a valid combination is found, it writes those brands into the Embedded Data fields (Brand1, Brand2, Brand3)

Then, in your Loop & Merge, instead of looping over the full brand list, you loop over these three embedded data values. That’s what enforces the logic.

I hope that clarifies.


Sorry for the late reply, I was away and the project was put on hold but now it’s back. There’s another complication to this question. 

The range of brands eligible for the loop and merge is one to more than three (if the brand list is 10 then max is 10). The eligibility is based on whether they used each brand within a certain time period. 

So, we cannot just randomly select 3 brands. Let’s say Brand A and Brand C are the only eligible brands and we cannot pair them together, we have to randomly select one of them and end up with only 1 brand in the loop and merge section. If we have 4 brands eligible, and A and C was initially selected as part of the max 3 brands, then we replace one of them with the 4th brand.  

 

I hope there is a solution for this. Thanks!

 


Hi ​@rarcega 

It’s not clear to me if the max number of brands in the L&M is 3 or 10, but here’s how I would go about this:

Add a hidden/autopunch (with custom js) selection question after your brands selection question using carry forward choices and choices randomization on the subset you want to exclude.

Qualtrics.SurveyEngine.addOnReady(function () {

this.getQuestionContainer().style.display = "none";
this.hidePreviousButton();
this.hideNextButton();
this.clickNextButton();

});

 

Use that hidden question displayed choices as the base for your L&M, randomizing the order and the presenting the number of loops you want.

 

You can add brands monthly and hide the ones you don’t want to show anymore in your initial brands selection question, as well as change the subset for exclusion.


The max brands for the loop and merge is 3.

 

Thanks! I’m going to try this out. I’m assuming that this will only work if there is only one set of brands that we don’t want to select together, right? 


Hi,

You could always add additional hidden carry forward questions, each managing its own exclusion subset.

Something like this:

  • Question 1: 10 brands
  • Question 2: Hidden carry forward question with selected choices from question 1, with subset on brands A & B.
  • Question 3: Hidden carry forward question with displayed choices from question 2, with subset on brands C & D.
  • ...

 But if you have too many exclusion subsets, it might be more efficient and less confusing at some point to use javascript to fill a hidden regular multiple answers question to use as your loop’s base.


Regarding your proposed solution of only limiting the loop and merge to 3 by using the “Present only 3 of total loops”, how will I keep track which ones were selected? Let’s say I need to create a dashboard of the results and I need to create a filter based on the brands asked inside the Loop and Merge.