Calculated fields: the result ready at the moment of collection

HashData Calculated Field runs a formula on the form responses and delivers averages, audit scores, indexes and conversions at the moment data is collected. The rule lives in the form, the same for every site, and nobody has to redo the math in a spreadsheet.

Good practices audit

Try it: change the answers and watch the score recalculate.

Uniforms and hair nets worn
Hand sanitizing at the entrance
Cold room temperature recorded
Bins with lid and pedal

Calculated field: audit score

83%

25 of 30 points across 3 items evaluated. “Not applicable” is left out of the calculation.

function calculateValue() {
  const items = findByTag('#item')
    .filter(r => hasContent(r.number));
  const points = items
    .reduce((s, r) => s + r.number, 0);
  return Math.round(
    points / (items.length * 10) * 100);
}

In short

Calculated Field is a HashData form element that runs a script formula on the previous responses and returns a number. It calculates averages, sums, percentage scores, risk indexes and conversions at the moment of collection, correctly ignores blank questions and lets you chain calculations, such as scores per section followed by an overall score.

Why calculate inside the form

In many operations, the digital form replaces paper only for data collection. The math is still done later, in a spreadsheet: the average of weight samples, the audit score, converting consumption into an indicator. Every manual step leaves room for formula, copy or version errors, and the result only shows up days later.

With Calculated Field, the calculation rule lives in the form itself. Whoever collects the data sees the result right away, and whoever analyzes it gets the number already calculated the same way at every site. If the rule changes, it is updated only once.

Which responses go into the calculation

Any response with a numeric value can be used. In choice questions, each option gets a value, which turns selections such as “Compliant” and “Non-compliant” into points.

Question typeValue used in the calculation
Integer, decimal and emoji quantityThe number entered
Single choice (dropdown, radio, buttons)The numeric value of the chosen option
Multiple choice and rankingThe values of the selected options and, for ranking, the position of each item
Rating (facial expressions, emojis)The rating value
Date, date and time, timeThe date or time entered
File uploadThe number of files uploaded
Text, email and geolocationText, labels and coordinates, to use as conditions in the calculation
Another calculated fieldThe result of the previous formula, to chain calculations

How the script works

Every formula is a function called calculateValue that returns a number or empty (null). The syntax is JavaScript/TypeScript, and the editor suggests question and function names with autocomplete (Ctrl+Space). Each question is accessed by its field name inside the resp object.

function calculateValue() {
    return (resp.sample_weight_1.number
          + resp.sample_weight_2.number
          + resp.sample_weight_3.number) / 3;
}

Calculation by tags

Tags group questions and keep the formula independent of individual names. Tag every weight question with #weight and use a single function. If the form gets a new sample, the formula stays correct without changes, and blank responses don’t distort the average.

function calculateValue() {
    return avgByTag('#weight');
}
FunctionWhat it does
avgByTagAverage of numeric responses with the given tags, ignoring empty ones
sumByTagSum of numeric responses with the tags
countByTagNumber of responses with the tags
maxByTag and minByTagHighest and lowest value among the responses with the tags
findByTagList of responses with the tags, for custom calculations
allList of all responses before the field
hasContent and isEmptyCheck whether a value is filled in

Calculated Field reads the questions placed before it in the form. That is why it must come after everything it uses.

Math library

The script supports intermediate variables, conditions, helper functions (including recursive ones) and the standard math library: rounding (round, floor, ceil, trunc), powers and roots (pow, sqrt, cbrt), logarithms and exponentials, trigonometric functions, max, min, abs and constants such as Math.PI and Math.E.

Everyday examples

Range between measurements

The difference between the highest and lowest temperature shows whether the process is stable, beyond the average.

function calculateValue() {
    const highest = maxByTag('#temperature');
    const lowest = minByTag('#temperature');
    if (highest === undefined || lowest === undefined) {
        return null;
    }
    return highest - lowest;
}

Risk index

Probability and severity are choice questions with values from 1 to 5; the index is the product of the two.

function calculateValue() {
    const p = resp.probability.number;
    const s = resp.severity.number;
    if (!hasContent(p) || !hasContent(s)) {
        return null;
    }
    return p * s;
}

Conversion with a factor

The consumption entered becomes the indicator the company reports. The factor is documented in the formula itself.

function calculateValue() {
    const consumption = resp.consumption_kwh.number;
    if (!hasContent(consumption)) {
        return null;
    }
    const factor = 0.0385; // illustrative factor
    return consumption * factor;
}

Evidence count

File upload questions are worth the number of files attached. The sum shows how many photos the inspection gathered.

function calculateValue() {
    return sumByTag('#evidence');
}

Use cases by industry

IndustryCalculationHow it is built
Food industryAverage weight and sample rangeWeight questions with a shared tag; average, maximum and minimum by tag
Quality and auditingScore per section and overall scoreOptions with values; one field per section and a final chained field
5S programScore per S and area totalOne tag per S; sum by tag and overall sum
Workplace safetyRisk indexProbability × severity from two choice questions
SustainabilityConverting consumption into an indicatorConsumption entered × factor defined in the formula
AgribusinessAverages and totals by field plot or lotField measurements aggregated by tag
LogisticsTemperature change between loading and deliverySubtraction between two numeric responses
Surveys and satisfactionAverage rating scoreScales and facial expressions with values; average by tag

Spreadsheet later or calculation at collection

SituationCalculating in a spreadsheet laterHashData Calculated Field
When the result appearsAfter export and reviewAt the moment of collection
Rule across sitesEach spreadsheet may have its own version of the formulaA single formula in the form
Blank questionsAverage divided by the total, with a distorted resultTag functions ignore empty responses
Rule changeUpdate every spreadsheetUpdate the form once
Auditing the mathScattered formulas and overwritten cellsA single, commented script alongside the form

Best practices

  • Give clear field names to the questions used in formulas, such as sample_weight_1.
  • Prefer tag functions over fixed lists of questions.
  • Use avgByTag for averages, never a sum divided by a fixed number.
  • Return empty when data is missing, instead of zero, so report averages are not distorted.
  • Place the field after all the questions it uses.
  • Test with response simulation before publishing, including skipped and blank questions.
  • Comment factors and constants in the script itself, with source and date.

The full technical reference, with every attribute and function, is at docs.hashdata.app.

Frequently asked questions

What is HashData Calculated Field?

It is a form element that runs a script formula on the previous responses and returns a number, such as an average, an audit score, an index or a conversion.

Do I need to know how to code?

Simple formulas, such as averages and sums by tag, fit on one line. More advanced calculations use JavaScript/TypeScript syntax, and the editor offers autocomplete with question and function names.

Which responses can go into the calculation?

Integers and decimals, emoji quantity, single and multiple choice with numeric values, ratings with facial expressions or emojis, dates and times, and the number of files uploaded. The script also reads text, option labels and geographic coordinates.

What happens if a question is left blank?

Tag functions such as avgByTag ignore empty responses, and the hasContent and isEmpty functions let you return empty when data is missing. That way, a skipped question doesn’t distort the average.

Can a calculated field use the result of another?

Yes. The result of a formula field is available as a numeric value to the fields placed after it, which lets you calculate scores per section and then the overall score.

See your calculations working in HashData

We’ll show you how to turn your operation’s scoring, averaging and conversion spreadsheets into formulas inside the form.

Scroll to Top