Skip to main content
Known Participant
December 27, 2022
Answered

Calculation

  • December 27, 2022
  • 1 reply
  • 1895 views

Trying to calcuate a few fields into one formula

I need a formula for the below:

("UnitTypeTally.0.0" * "#ofUnitsTally.0.0") + ("TotalTally.0.0") 

("UnitTypeTally.0.1" * "#ofUnitsTally.0.1") + ("TotalTally.0.1") 

.......

("UnitTypeTally.0.15" * "#ofUnitsTally.0.15") + ("TotalTally.0.15") 

This topic has been closed for replies.
Correct answer Nesa Nurani

try like this:

var a = Number(this.getField("UnitTypeTally.0.0").valueAsString);
var b = Number(this.getField("#ofUnitsTally.0.0").valueAsString);
var c = Number(this.getField("TotalTally.0.0").valueAsString);
if(a&&b&&c)
event.value = a*b+c;
else
event.value = "";

1 reply

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
December 27, 2022

try like this:

var a = Number(this.getField("UnitTypeTally.0.0").valueAsString);
var b = Number(this.getField("#ofUnitsTally.0.0").valueAsString);
var c = Number(this.getField("TotalTally.0.0").valueAsString);
if(a&&b&&c)
event.value = a*b+c;
else
event.value = "";

try67
Community Expert
December 28, 2022

This will not produce a result if any of the fields is zero or empty, though. That's no necessarily how you want such a sum to work...

Nesa Nurani
Community Expert
December 28, 2022

I tried the above and it didn't work. UnitTypeTally.0.0 is a dropdown where each has option has an output value. Does that attribute to it not working? Because even with something entered into all fields, it didn't return a number


It should still work if you added number as export value for dropdown choice.

It will calculate when all 3 fields have a value.

Do you have any error in console?

Can you share your file with us?