Error with 'count-non-empty'

Hi all,
I have a form with a repeat_group where I collect some information among which there's the height (cm, integer) and weight (kg, decimal) of my target.
At the end of the repeat, I would like to calculate automatically the average of the group for both the variables, so I added a calculate field using sum(${field}) div count(${field}).
Due to the fact that the weight field is not mandatory, I use count-non-empty() instead of count() but I get the following validation error message from XLSForm online:

Error: b"ODK Validate Errors:\n>> Something broke the parser. See above for a hint.\nError evaluating field 'weight_mean': The problem was located in calculate expression for ${weight_mean}\nXPath evaluation: type mismatch \nconverting to numeric\nCaused by: org.javarosa.xpath.XPathTypeMismatchException: The problem was located in calculate expression for ${weight_mean}\nXPath evaluation: type mismatch \nconverting to numeric\n\t... 11 more\n\nThe following files failed validation:\n${test}.xml\n\nResult: Invalid"

I read around the forum and found this.
I tested a bit trying different approaches, among which using sum(coaleasce(${field},0)) but I get another error (i.e. not a nodeset). So this let's me think about a possible bug related to count-non-empty() or something else related to decimal(). Any idea or suggestions?

I'm using version 1.24 .

Attached an example form.
test.xlsx (49.7 KB)

Thanks in advance!

Hi @spono,

I haven´t used count-non-empty before so I do not it error you got it is a current bug or misused. Perhaps @LN could confirm about this.

Workaround I use to count non empty is just to include an if(${question_in_repeats} !='' then set as 1 otherwise 0 and out of repeat group just sum 1s:

You can see this form in sandbox as TestConteo

Hi @spono

thanks for reporting the issue. I took a look at it and the first problem is with the converter which can't handle that function. I reported the issue here:
You could try to convert the form without that function and the add it manually to an xml version but unfortunately there is also a bug in Javarosa which I reported here:

We will try to fix it.

1 Like

Perfect, good to know @Grzesiek2010!
I'll take a look to @Alexander_Torrado's solution in the meantime.

Thanks a lot both for the support!

1 Like