# How can I make ODK categorise my calculated questionnaire scores?

HI everyone!
I would really appreciate any help on this!
As part of my project I am asking several questionnaires and would like to calculate their scores as I go. No problem so far.
Once I arrive at the final score I would like ODK to automatically categorise the score and assign a weighted score which I will then sum at the end.

QuestionnaireA scores 0-14=0, 15-18=2, 19-20=4
QuestionnaireB scores 0-4=2, 5-7=1, 8-12=0
Sum of the category for QuestionnaireA + QuestionnaireB out of maximum 6 points.

This should be easy, but at the moment I have resorted to asking the person entering the data to manually categorise the scores.
Any advice would be really appreciated!
Thanks. Best wishes, Grace

You could probably find more fancy/complicated ways to do this, but I'd
probably just do:

if(\${scoresa} >= 0 and < 15, 0, if(\${scoresa} >= 15 and < 19, 2,
if(\${scoresa} >= 19 and < 21, 4, "SCORE COULD NOT BE CALCULATED")))

or something like that.

Jason

··· On Tuesday, January 10, 2017 at 2:47:16 PM UTC-5, emma.gra...@googlemail.com wrote: > > HI everyone! > I would really appreciate any help on this! > As part of my project I am asking several questionnaires and would like to > calculate their scores as I go. No problem so far. > Once I arrive at the final score I would like ODK to automatically > categorise the score and assign a weighted score which I will then sum at > the end. > > QuestionnaireA scores 0-14=0, 15-18=2, 19-20=4 > QuestionnaireB scores 0-4=2, 5-7=1, 8-12=0 > Sum of the category for QuestionnaireA + QuestionnaireB out of maximum 6 > points. > > This should be easy, but at the moment I have resorted to asking the > person entering the data to manually categorise the scores. > Any advice would be really appreciated! > Thanks. Best wishes, Grace

Dear Jason,
Thanks very much for your response!
I've tried it exactly the way you suggested and a few other variations, with and without an = sign before the categories, and with the brackets in different places, but no luck yet!
calc_bi_total_fa is the name given in the above column where the questionnaire scores are totalled.

if (\${calc_bi_total_fa} >=0 and <=14)= 4, if(\${calc_bi_total_fa}>=15 and <=18)= 2, if(\${calc_bi_total_fa}>=19 and<=20)= 0

Invalid calculate for the bind attached to "\${bfit_bi_score}" : Bad node: org.javarosa.xpath.parser.ast.ASTNodeAbstractExpr@34033bd0 in expression if ( \${calc_bi_total_fa} >=0 and <=14)= 4, if( \${calc_bi_total_fa} >=15 and <=18)= 2, if( \${calc_bi_total_fa} >=19 and<=20)= 0

I am putting this code into the calculation column. Any other ideas?!
Best wishes, Grace

··· On Wednesday, 11 January 2017 16:45:35 UTC, Jason Ives wrote: > You could probably find more fancy/complicated ways to do this, but I'd probably just do: > > > if(\${scoresa} >= 0 and < 15, 0, if(\${scoresa} >= 15 and < 19, 2, if(\${scoresa} >= 19 and < 21, 4, "SCORE COULD NOT BE CALCULATED"))) > > > or something like that. > > > Jason > > On Tuesday, January 10, 2017 at 2:47:16 PM UTC-5, emma.gra...@googlemail.com wrote:HI everyone! > > I would really appreciate any help on this! > > As part of my project I am asking several questionnaires and would like to calculate their scores as I go. No problem so far. > > Once I arrive at the final score I would like ODK to automatically categorise the score and assign a weighted score which I will then sum at the end. > > > > QuestionnaireA scores 0-14=0, 15-18=2, 19-20=4 > > QuestionnaireB scores 0-4=2, 5-7=1, 8-12=0 > > Sum of the category for QuestionnaireA + QuestionnaireB out of maximum 6 points. > > > > This should be easy, but at the moment I have resorted to asking the person entering the data to manually categorise the scores. > > Any advice would be really appreciated! > > Thanks. Best wishes, Grace

Hi Grace,

For your own sanity, I'd recommend you break down the calculations
into separate values, then test and total those. So you'd have three
rows with these calculations...

if((\${calc_bi_total_fa}>=0 and \${calc_bi_total_fa}<=14), 0, 0)
if((\${calc_bi_total_fa}>=15 and \${calc_bi_total_fa}<=18), 2, 0)
if((\${calc_bi_total_fa}>=19 and \${calc_bi_total_fa}<=20), 4, 0)

Yaw