Using double brackets in calculations

Hi everyone,

Does anyone know if using double brackets in the 'calculate' section works?

I attach my form for reference.

You will see that in cell N37 and N38 I have tried to use double brackets so these two factors are multiplied together first, before I add the final factor.

Any advice much appreciated as usual.

Fran

PilotSurveyArtisanalFisheriesSierraLeoneNEW2.xls (272.5 KB)

Hi,

Try using the following:

(${numberofbowls}*${weightofbowl})+${weightofindividual}

1 Like

Please note using brackets is not necessary in this example, because the order of precedence of XPath operators means the multiplication will be performed before the addition. See http://saxon.sourceforge.net/saxon6.5.5/expressions.html#VariableReferences

Indeed, ${weightofindividual}+${numberofbowls}*${weightofbowl} should give you the same result. You only really need brackets when you need to override the default operator precedence (or to make it explicit to the casual reader...)

4 Likes

HELLO, you don’t need brackets here, there’s order operation already defined in this language.

1 Like

Hi there - sorry that only generated blank fields for me

Hi Gareth -

I tried using the following as you suggested:

${weightofindividual}+${numberofbowls}*${weightofbowl}

${priceofindividual}+${numberofbowls}*${priceofbowl}

but they stopped my form being exported from the server.

@abdoul @Xiphware @jruizc @yanokwa

Hi everyone :slight_smile:

I attach my form here again. PilotSurveyArtisanalFisheriesSierraLeoneNEW2.xls (283.5 KB)

The formulas I have as suggested by @Xiphware in N37 and N38, are stopping my CSVs from being exported by ODK Breifcase onto my computer

The formulas suggested by @jruizc allow my CSVs to be downloaded but contain no data under the column headings in the export

Thanks in advance for your advice.

Fran

Hi,

@Xiphware @abdoul Thanks for the observation. It is something that I didn't consider.

@Frances The problem you are having with my formula (no data) is something that I have experienced before with big operations. My solution was to have a two or more rows for different steps of the operation.
In your case, this would mean one row for the multiplication and one for the addition.

However, considering you already have the multiplication in N35 and N36, you can use the followings for N37 and N38:

${weightofindividual}+${totalcatchbowl}
${priceofindividual}+${totalvaluebowl}

Regarding ODK Briefcase, I don't have much experience with it. Maybe someone else can confirm if this is a know or yet to be reported problem.

Good luck with your form!

Hi @jruizc - I used those formulas you just suggested and again, the exported CSV file does not contain any resulting columns.

I think it might be because I am using a 'name' from a calculate row and not an integer or decimal row?

@yanokwa @abdoul @Xiphware

Let's tease out where the problem is first. Do you see the data you want in Aggregate's web UI? And when you say exported CSV are you using Aggregate's export or are you downloading to Briefcase and then exporting from there?

Also, no need to tag folks in the thread. If they've already responded, they generally get notified :slight_smile:

Hi,

I just notice the following:

Inside your repeat group the questions you ask depend if it is either a bowl or an individual

  • Rows 30, 31, 32 for bowl
  • Rows 33 and 34 for individual

However, your calculations in rows 37 and 38 is adding the results of both bowls and individuals. This means there will always be an empty value or NaN in the calculation.

Wouldn't rows 37 and 38 be the same as rows 33 and 34 if the user selects "Individuals"?

Ah yes perhaps they would be the same.

Does this then mean that I cannot do this calculation in this form?

I basically want to calculate the total catch per fish landing, so perhaps this is something I will have to incorporate in the supporting database?

Fran

Hi there - yes I see the data on the UI, and I am downloading to my computer using breifcase.

I attach what one of the exported CSVs looks like Frantestform3_speciescatchgroup.csv (588 Bytes)

You will see that the total catch and total value columns are left blank in the export.

Here is the supporting form:
Frantestform3.xls (276.5 KB)

@jruizc's reply also highlight what the issue might be.

What do you think?

Many thanks,

Fran

1 Like

I believe the problem has to do with relevance and it's a bit subtle.

If bowlorindividual is 2, then numberofbowls, weightofbowl, and priceofbowl are not relevant. And if they are not relevant, they are blank in the calculations for totalvaluebowl and totalcatchbowl. So, blank * whatever = blank. That's what you are seeing in the output CSV>

Calculation inputs that are not required or can be irrelevant can be blank and so you need to account for that in your calculation. So something like this: if(${numberofbowls}='',0,${numberofbowls})*${priceofbowl} should work.

Hi Yaw,

Thanks for this. I tried adding your suggestions to the sheet but unfortunately I got blank outputs again.

Please see my attach form for what I included.
Frantestform4.xls (276.5 KB)

Fran

A post was split to a new topic: What happens when a node is not relevant

The example I gave wasn't complete and that's why it didn't work.

Everywhere there is an irrelevant value has to have that calculation, so this:
if(${numberofbowls}='',0,${numberofbowls})*if(${weightofbowl}='',0,${weightofbowl}) +${weightofindividual}

I've attached a working example.

relevant_calculation.xls (23 KB)

1 Like

And these if function should also be used in the ${totalvaluebowl} and ${totalcatchbowl} fields in their calculation columns.

Hi Yaw - I tried these formulas and my export file now shows data in the 'totalvalue' and 'totalcatch' columns, however, they are simply a repeat of the data in columns F and G. The calculations only include the data from the individual catches and not the bowls. Therefore it does not show TOTAL catch.

See the export file
Frantestform5_speciescatchgroup.csv (667 Bytes)

and the form
Frantestform5.xls (276.5 KB)

Sorry for this never ending saga! :slight_smile:

Fran