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.
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 type | Value used in the calculation |
|---|---|
| Integer, decimal and emoji quantity | The number entered |
| Single choice (dropdown, radio, buttons) | The numeric value of the chosen option |
| Multiple choice and ranking | The values of the selected options and, for ranking, the position of each item |
| Rating (facial expressions, emojis) | The rating value |
| Date, date and time, time | The date or time entered |
| File upload | The number of files uploaded |
| Text, email and geolocation | Text, labels and coordinates, to use as conditions in the calculation |
| Another calculated field | The 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');
}| Function | What it does |
|---|---|
avgByTag | Average of numeric responses with the given tags, ignoring empty ones |
sumByTag | Sum of numeric responses with the tags |
countByTag | Number of responses with the tags |
maxByTag and minByTag | Highest and lowest value among the responses with the tags |
findByTag | List of responses with the tags, for custom calculations |
all | List of all responses before the field |
hasContent and isEmpty | Check 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
| Industry | Calculation | How it is built |
|---|---|---|
| Food industry | Average weight and sample range | Weight questions with a shared tag; average, maximum and minimum by tag |
| Quality and auditing | Score per section and overall score | Options with values; one field per section and a final chained field |
| 5S program | Score per S and area total | One tag per S; sum by tag and overall sum |
| Workplace safety | Risk index | Probability × severity from two choice questions |
| Sustainability | Converting consumption into an indicator | Consumption entered × factor defined in the formula |
| Agribusiness | Averages and totals by field plot or lot | Field measurements aggregated by tag |
| Logistics | Temperature change between loading and delivery | Subtraction between two numeric responses |
| Surveys and satisfaction | Average rating score | Scales and facial expressions with values; average by tag |
Spreadsheet later or calculation at collection
| Situation | Calculating in a spreadsheet later | HashData Calculated Field |
|---|---|---|
| When the result appears | After export and review | At the moment of collection |
| Rule across sites | Each spreadsheet may have its own version of the formula | A single formula in the form |
| Blank questions | Average divided by the total, with a distorted result | Tag functions ignore empty responses |
| Rule change | Update every spreadsheet | Update the form once |
| Auditing the math | Scattered formulas and overwritten cells | A 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
avgByTagfor 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.