Adding scores to answers and summing up for final result

Hi,
I have a survey with several multi-select and single-select questions types. I want to score specific answers. I use following approach:

  • create Variable of type integer: bspScoreMulti
  • Expression:

new[]
{
sellThrough.Contains(1)?1:0,
sellThrough.Contains(2)?2:0,
sellThrough.Contains(3)?0:0,
}.Sum()

Static text: “Your Score for this section is:%bpsScoreSingle% + %bpsScoreMulti% = %bpsScoreSum%”

With single select fields everything is working fine. I have problem with multi-select. In case of no answer to sellThrough , %bspScoreMulti% = […] and cannot be calculated. When I make a selection then it becomes an integer. How can I set bspScoreMulti to 0 if there is no answer?

Use function ContainsAny() istead of Contains() in this case.

Contains() is written by Microsoft (part of standard C#) and requires the object to be initialized (not null) or in Survey Solutions terms the question must be answered, before you can probe it like this.

ContainsAny() is written by our team (Survey Solutions specific) and should tolerate the case where the question is not answered.

Alternatively you could have written:
IsAnswered(sellThrough)?(your expression goes here):0

Finally, your multiselect contains ‘None of the options above’ item, so the multiselect MUST be answered (something checked) regardless of the situation of the respondent and as soon as it is answered the original expression should work just as well.

Also the message displaying the section score should probably be at the END of the section, not in the beginning, or perhaps even all scores in their own dedicated score summary section, but that is up to you.

Best, Sergiy Radyakin

2 Likes

Hi Sergiy,
thank you for your instructions. This helped me a lot and solved my problem.
Concerning the message displaying the score, I have put it there just for testing purpose. Once finished, the score will be displayed within a separate section.

Regards,
Petar

But no I have another problem with my scoring structure. I want to give 1 point for an answered questions, regardless of the selection. In this case, I have a multi-select combo box with which the user can select one or many of 227 countries:

I was trying to score the question with:
IsAnswered(sellToCountry)?1:0

But no success. Please help. TNX!

br,
Petar

I don’t understand this:

Be specific.

Note also that @wadesoga is also doing a questionnaire with scoring and having some troubles displaying the messages.

@Petar, perhaps, you could work together and add up your knowledge to come up with a better version of each questionnaire?

It is not adding a 1-point-score to the question. Whatever selection the user makes, should results with one point in scoring.
hope this clarifies my issue.

Petar

No it doesn’t.
The expression is obviously correct, but it matters where you’ve written it, what else is written next to it, etc, etc, etc.

For the moment my best guess is you are referring to the wrong question in the IsAnswered() function. But it could be anything.

Please, post the PDF of this questionnaire somewhere so that the whole questionnaire can be understood, or upload the questionnaire to the demo server where this can be tested.

I’ll add the survey later to the demo server. For now, I’m using it within a custom variable (long integer) - expression:

new[]
{
//Multi-Select Questions
sellThrough.ContainsAny(1)?1:0,
sellThrough.ContainsAny(2)?2:0,
sellThrough.ContainsAny(3)?0:0,

**IsAnswered(sellToCountry)?1:0,**

setPrices.ContainsAny(1)?1:0,
setPrices.ContainsAny(2)?1:0,
setPrices.ContainsAny(3)?1:0,
setPrices.ContainsAny(4)?1:0,
setPrices.ContainsAny(5)?1:0,
setPrices.ContainsAny(6)?0:0,


//Single-Select Questions
avgmsv==(2)?2:0,
avgmsv==(3)?3:0,
avgmsv==(4)?4:0,
avgmsv==(5)?5:0,

avgmt==(1)?1:0,
avgmt==(2)?2:0,
avgmt==(3)?3:0,
avgmt==(4)?4:0,
avgmt==(5)?5:0,
avgmt==(6)?6:0,

onlineAvgmsv==(1)?1:0,
onlineAvgmsv==(2)?2:0,
onlineAvgmsv==(3)?3:0,
onlineAvgmsv==(4)?4:0,
onlineAvgmsv==(5)?5:0,

onlineAvgmt==(1)?1:0,
onlineAvgmt==(2)?2:0,
onlineAvgmt==(3)?3:0,
onlineAvgmt==(4)?4:0,
onlineAvgmt==(5)?5:0,
onlineAvgmt==(6)?6:0,

majoritySales==(1)?1:0,
majoritySales==(2)?1:0,
majoritySales==(3)?1:0,

qualityStandards==(1)?1:0,
qualityStandards==(2)?1:0,

demandResponseRate==(1)?3:0,
demandResponseRate==(2)?2:0,
demandResponseRate==(3)?1:0,
demandResponseRate==(4)?0:0,

calcAvgProductCost==(1)?1:0,
calcAvgProductCost==(2)?0:0,
calcAvgProductCost==(3)?0:0,

calcEcomProfit==(1)?1:0,
calcEcomProfit==(2)?0:0,

onlineMarketDemand==(1)?1:0,
onlineMarketDemand==(2)?1:0,
onlineMarketDemand==(3)?1:0,
onlineMarketDemand==(4)?1:0,

customerType==(1)?1:0,
customerType==(2)?0:0,

valueProposition==(1)?1:0,
valueProposition==(2)?0:0,
valueProposition==(3)?0:0,

eComMarketingMix==(1)?2:0,
eComMarketingMix==(2)?1:0,
eComMarketingMix==(3)?0:0,
eComMarketingMix==(4)?0:0,

competitorResearch==(1)?1:0,
competitorResearch==(2)?0:0,

trademark==(1)?1:0,
trademark==(2)?0:0,

eComLaws==(1)?3:0,
eComLaws==(2)?2:0,
eComLaws==(3)?2:0,
eComLaws==(4)?1:0,
eComLaws==(5)?0:0,

}.Sum()

and it should work beautifully, just don’t end your scores with a comma.

it’s
new[]{a,b,c}.Sum()
not
new[]{a,b,c,}.Sum()

Best, Sergiy

Unfortunately, it is still not working. I have uploaded the survey to the demo server:
https://demo.mysurvey.solutions/WebInterview/MDBXUECL/Start

br,
Petar

Works for me:

score1

Everything is working except:

Section: Business planning and strategy
Question: Which countries does your online business sell to?
(HINT: to enable this question you must answer positively to “Does your business sell through:”)

When adding one or more countries to the list, the score must add 1 point to the counter.

br,
Petar

and it does:


(click on the image to see full image)

This is good… Gone through the thread. @Petar questionnaire is a bit complex than mine but looked through the sum expression and it looked fine and should work.
@sergiy what i need now is to be able to show a certain text based on the sum.
if SUM is 70 and above, show AB
if SUM is 50-69, show C1
etc…

@Petar can you please share the code you used to show certain text based on the Total Score?..

Thanks.

@wadesoga sorry for my late reply. I totally missed you question.

I use an enabling condition within static text, eg.:
totalScore <= 41 -> shows TEXT 1
totalScore >= 42 && totalScore < 166 -> shows TEXT 2
totalScore > 165 -> shows TEXT 3

The scores I have calculated as described above.

Petar

Okay… Thanks @Petar Can you help with the enabling condition coding suppose:
Text 1 is AB
Text 2 is C1… etc
waiting for your reply…
Thanks.

@wadesoga, the text does not affect the condition. You can type any text you want, as long as it corresponds to the condition by meaning.
So if the condition is SCORE<42 then the message should be “The score is less than 42

@sergiy, it didn’t work as i expected it to… Here what i would really prefer to be able to do, to create a question or static text that allow the following condition, am not sure if i got the condition right. I would be glad if i can get help to get correct enabling condition to use:
“Self” is a question with option codes i want to be displayed for each score, while “SumOpt” is the total score…

SumOpt => 70;self== 1
SumOpt InRange(56,69);self== 2
SumOpt inRange(35,55);self== 3
SumOpt =< 34;self== 4

Thanks.