Howdy y'all and a whole lot of apologizing from this end ... I've been heads down on a completely unrelated project (helping two large companies merge - and organizing all the data integration projects - oy!) and piling up things I would love to share. If only there were enough hours in the day to do all this, sleep and entertain an 8 year old lol.. This time around, I'm going to highlight a recent solution I provided to a Typeform Community member: Question: I would like the quiz-taker to receive one primary result and one secondary result. Where it gets tricky is that there are 6 results and 2 of them are for the primary result and 4 for the secondary result. So I haven’t figured out a way to ensure the 1st result is from the 2 primary results and the secondary result is from the other 4. Then when I thought I had it, someone tied and got 2 secondary results with a 50/50 split. Can what I’m looking for be done with typeform? My response - that actually works btw: |

Looks like you have 8 possible ‘endings’:

- Primary1 + secondary1
- Primary1 + secondary2
- Primary1 + secondary3
- Primary1 + secondary4
- Primary2 + secondary1
- Primary2 + secondary2
- Primary2 + secondary3
- Primary2 + secondary4

Your logic rules have to look for the primary answer first - which one has the highest (assumed) score?

- logic rules something like this:
- if Primary1 (subtotal) is greater than 0 add primary1 to p1_v_p2 (a comparison variable)
- if Primary 2 is greater than 0 subtract primary2 from p1_v_p2
- if p1_v_p2 is greater than 0 (which means primary1 score is highest) replace p_choice (a text variable) with p1
- if p1_v_p2 is less than 0 replace p_choice with p2
- if p1_v_p2 = 0 go to a tie breaker question (to get a selection made - if ties are at all possible)

That will give you the primary selection

Next you have to evaluate the possible selections for the secondary winner - I am going to use s1, s2 etc for the variable names to reduce typing. You are going to have to put in logic to determine if there is a unique high (assumed) secondary score and deal withe ties.

There are a number of variables that I will show below that you would need to create to compare the secondary scores to each other. But first here’s the basic of what needs to be done in logic rules:

- if s1 is greater than s2 and s1 greater than s3 and s1 greater than s4 then s1 is the unique high score (s1 has a count of being higher than another value 3 times - this will come into play below)
- same if s2 is greater than the other 3, etc.

- the sets of rules we need to do this will have to compare the following pairings in order to get the count of ‘higher than’ for each variable
- s1-s2, s1-s3, s1-s4,
- s2-s3, s2-s4
- s3-s4

- here’s the style of logic to use to get the ‘count of higher than’ -
- note gt= greater than, lt = less than,
- if s1 gt 0 add s1 to s1_v_s2
- if s2 gt 0 subtract s2 from s1_v_s2
- if s1_v_s2 gt 0 add 1 to s1_count
- if s1_v_s2 lt 0 add 1 to s2_count
**(this needs to be repeated for all the combinations - i’ll do the next one then you can figure out the rest)**- if s1 gt 0 add s1 to s1_v_s3
- if s3 gt 0 subtract s3 from s1_v_s3
- if s1_v_s3 gt 0 add 1 to s1_count
- if s1_v_s3 lt 0 add 1 to s3_count
- repeat for all the pairings above

- now we look at the sX_count variables to see if there is a unique high score of 3 - which is the highest count it could get from the above
- if s1_count = 3 replace s_choice with secondary1
- if s2_count =3 replace s_choice with secondary2
- if s3_count =3 replace s_choice with secondary3
- if s4_count = 3 replace s_choice with secondary4

- what happens if there are no 3 counts? you have to determine if there is a unique count at 2 - there could be some cases where the values are tied and no points would have been added to an sX_count variable.
- if s1_count = 2 and s2_count lt 2 and s3_count lt 2 and s4_count lt 2 then replace s_choice with secondary1
- s1_count is uniquely high at a count of 2

- repeat for s2_count = 2 and the others lt 2, s3_count = 2 and others lt 2 and s3_count = 2 and others lt 2
- that will cover all the unique high counts at 2

- if s1_count = 2 and s2_count lt 2 and s3_count lt 2 and s4_count lt 2 then replace s_choice with secondary1
- now to look at ties at the 2 count level - you need to look at rules like this to go to a tiebreaker question for the items that are tied:
- if s1_count = 2 and s2_count =2 and s3+count lt 2 and s4_count lt 2 go to s1-s2 tiebreaker
- if s1_count = 2 and s3_count -2 and s1_count lt 2 and s4_count lt 2 go to s1-s3 tiebreaker
- repeat to cover off all the possible pairs that could be tied at 2 - with only 4 possible secondary values, you only need to look at pairs
- if there is a tiebreaker question you would use a logic rule to set the s_choice variable to the appropriate value that was selected

- if there are counts of 2 - which is possible in the case of the sx_v_sx = 0 for scores - you wold have to do the same type of evaluatoin at sX_counts of 1
- here you would evaluate pairs and then the triplets for = 1 counts and if unique at 1 you have your secondary choice if there are ties, you have another set of tie breakers - you can use the same pair tiebreaker questions as above, but you need to test
- if s1_count =1 and s2_count =1 and s3_count = 1 and s4_count lt 1 then go to s1-s2-s3 tiebreaker
- the combinations to test would be
- s1,s2,s3
- s1, s2, s4
- s2, s3, s4

- the combinations to test would be

- if s1_count =1 and s2_count =1 and s3_count = 1 and s4_count lt 1 then go to s1-s2-s3 tiebreaker

- here you would evaluate pairs and then the triplets for = 1 counts and if unique at 1 you have your secondary choice if there are ties, you have another set of tie breakers - you can use the same pair tiebreaker questions as above, but you need to test
- if the s_counts are all = 0 then you have a coin toss or a scoring issue lol

- note gt= greater than, lt = less than,

After all that .. you have the p_choice and the s_choice identified and you can use the logic rules like this to go to the ‘combined ending’ you are seeking

- if p_choice = primary1 and s_choice = secondary1 go to that ending (p1-s1)
- if p_choice = primary1 and s_choice = secondary2 go to that ending (p1-s2)
- etc.

That may seem like a convoluted way to do this but with 4 totals to compare it’s fairly easy to get through the tiebreaker comparisons - if you have 6 variables, you have about 150+ possible tiebreakers to check for and pages to create. lol.

Hope that helps make it easier to understand.

des