Visibility of a row in a matrix table question based on multiple conditions (as filter)

Hello everyone,

In a Kobo question matrix, I would like some matrix rows (questions) to be visible based on a calculation which is done based on previous answers.

The previous answers which are used for the calculations are:

  1. total farm area (which includes conventional and organic farm area),
  2. organic farm area (which should be lesser than the total farm area).

The Kobo question matrix has two questions (on different rows), with the same column (seed price):

  1. Row 1: Price of conventional seeds?
    This should appear only if the total farm area > organic farm area. In my XLSForm this condition is ${area_cotton} > ${organic_cotton}
  2. Row 2: Price of organic seeds?
    This should appear only if there is some organic farm area. In my XLSForm, this condition is ${organic_cotton} > 0.

Somehow I am still getting both the rows irrespective of my calculation and choice_filters. Could you please let me know where I am going wrong?
20221104_trial_matrix_with_filter_2_conditions.xlsx (11.1 KB)

Thanks very much in advance,
Soham

Hi @sohamadla, I think the first question this raises for me is if these two questions are mutually exclusive, or if there are times when both would apply?

For example, say my total farm is 3 ha and my organic farm is 1 ha.

In this case, the ${area_cotton} > ${organic_cotton} is true.

AND ${organic_cotton} > 0 is also true.

So, in this case, do you want both questions to appear?

Without testing, it looks from your XLSForm like you’re applying an if statement with both those conditions, so if the first statement is true, then it will only ever apply the number “1” based on your if statement.

Can you confirm… Do you only want your form to ask one or the other question? Or do you want both questions to appear if both logic statements are true?

Sorry if I’ve misunderstood something, but perhaps a bit more clarification on what you’re trying to make happen, with an example, might help.

Thanks!
Janna

Thank you for looking at this so carefully, @janna! Yes, these questions are indeed not mutually exclusive, and there is definitely the possibility of both conditions being true (just like a farmer can have both conventional and organic farm areas within their total farm area).

  1. List item In your example (total farm area = 3ha, organic farm area = 1ha), I would like both the questions to appear.
  2. List item If total farm area = 3ha and organic farm area = 0ha, I would like only Row 1 (Price of conventional seeds) to appear.
  3. List item If total farm area = 3ha and organic farm area = 3ha, I would like only Row 2 (Price of organic seeds) to appear.

I think I am doing something wrong in either on the “survey” sheet (columns “calculation” or “choice_filter”), or in the “choices” sheet (column “filter”). I’d really appreciate if someone can correct these.

Currently I’m getting the following error:

Blockquote * FormLogicError: Could not evaluate: if(( /model/instance[1]/aBXktt44cVEnGgMJuh7UGy/organic_cotton >0),1,if(( /model/instance[1]/aBXktt44cVEnGgMJuh7UGy/area_cotton > /model/instance[1]/aBXktt44cVEnGgMJuh7UGy/organic_cotton ,2),0),0), message: Expected one token, but found: 3{“stack”:[{“t”:“root”,“tokens”:[]},{“v”:“if”,“t”:“fn”,“dead”:false,“tokens”:[{“t”:“bool”,“v”:false},“,”,{“t”:“num”,“str”:“1”,“v”:1},“,”]},{“v”:“if”,“t”:“fn”,“dead”:false,“tokens”:[]}],“cur”:{“v”:“”,“t”:“fn”,“dead”:false,“tokens”:[{“t”:“bool”,“v”:false},“,”,{“t”:“num”,“str”:“2”,“v”:2}]}}

Hi @sohamadla ,

I was able to take a look at your XLSForm.

Hopefully this helps, but the solution looks quite different to what was in your original file, so here are a few notes that might be helpful:

  1. You don’t need a choice filter unless you are using a select-type of question.
  2. For making the follow-up questions (about pricing) appear or disappear based on the previous acreage entered, you want to rely on your ‘skip logic’ instead of choice filters.
  3. You don’t need a calculation with an if statement to apply 1/2/0 = you can just make logic statements such as ‘if total area is bigger than organic area, then make the ‘conventional’ pricing question appear’.

Take a look at the attached XLSForm and see how this works for you, and if it is what you’re looking for:
aKkPeFaApWCLT7Rug5iGPi.xlsx (10.9 KB)

Here’s also a quick video that shows how the form works:
Animated thumbnail for video
Watch Video

Cheers,
Janna