Conditional logic for default choice equation | XM Community
Skip to main content

Hello,

I’m trying to create default choices based on previous responses, but there’s a math challenge. Here are the questions

  1. When did you first engage in BEHAVIOR (age in years)? 
  2. When was the last time you engaged in BEHAVIOR (age in years)?
  3. How many times did you engage in BEHAVIOR in the last week?
  4. ‘’ ‘’ Last month?
  5. Last year?
  6. Lifetime?

Questions 3-5 are no problem I just multiply question 3 by the appropriate amount (4, 52). The trouble is question 6 where ideally it would be the #5 * (#2 - #1), but if they were the same age the first and last time they engaged in the behavior then it reads: #5 * 0

I tried creating a branch where if the difference (called B Years below) = 0 an embedded data field (B Lifetime) = 1 and if B Years > 0 then B Years = B Lifetime, so that the equation becomes #5 * (B Lifetime). 

Branching logic for conditional math

However, it doesn’t seem to work and I’m not sure why... All the other calculated fields are after a page break and work just fine. Any help is very much appreciated.

Hey @ruorka not sure if i understood it correct but if you are calculating ‘B years’ using this - 

 

accordingly the next branch logic should be ‘if B years = 0’ instead of ‘SI years = 0’

here, replace ‘SI years’ with ‘B years’

is that correct?


@omkarkewat 

Sorry, I changed the variable names to be clearer but forgot to change the branch logic variable name for clarity as well. 

 


@ruorka did it work now? if not, then can you specify what error you are facing, perhaps attach some more snapshots of the error!


@omkarkewat That’s how it was originally. The problem is that when SI Years = 0, it’s not actually branching to equal 1, so the calculation in the default choice field ends up being zero ( #5 * 0)


@ruorka your setup looks perfect that is mentioned in the screenshot because it works for me when i replicated at my end. i am assuming its just a silly mistake in your flow or in the survey builder, few things you can double check are - 

  1. you are using the correct Question for the calculation
  2. you are using the correct pipe text
  3. you are using the correct embedded data for the calculation
  4. the branch logics in the survey flow are created after the respective question block.

even if it doesn’t work then try raising a Qualtrics ticket.


Leave a Reply