{"record":{"id":"253787be60756528","repo":"pentaho/pentaho-kettle","slug":"error-calculate-formula-formula","errorCode":null,"errorMessage":"Error calculate formula. Formula ","messagePattern":"Error calculate formula\\. Formula ","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/formula/Formula.java","lineNumber":145,"sourceCode":"          } else {\n            throw new KettleException( \"Unable to find field name for formula [\"\n              + Const.NVL( fn.getFormula(), \"\" ) + \"]\" );\n          }\n        }\n      }\n\n      for ( int i = 0; i < meta.getFormula().length; i++ ) {\n        FormulaMetaFunction fn = meta.getFormula()[i];\n        if ( !Utils.isEmpty( fn.getFieldName() ) ) {\n          if ( data.formulas[i] == null ) {\n            data.formulas[i] = data.createFormula( meta.getFormula()[i].getFormula() );\n          }\n\n          // this is main part of all this step: calculate formula\n          Object formulaResult = data.formulas[i].evaluate();\n          if ( formulaResult instanceof LibFormulaErrorValue ) {\n            // inspect why it is happens to get clear error message.\n            throw new KettleException( \"Error calculate formula. Formula \"\n                + fn.getFormula() + \" output field: \" + fn.getFieldName() + \", error is: \" + formulaResult.toString() );\n          }\n\n          // Calculate the return type on the first row...\n          // for most cases we can try to convert data on a fly.\n          if ( data.returnType[i] < 0 ) {\n            if ( formulaResult instanceof String ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_STRING;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_STRING );\n            } else if ( formulaResult instanceof Integer ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_INTEGER;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_INTEGER );\n            } else if ( formulaResult instanceof Long ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_LONG;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_INTEGER );\n            } else if ( formulaResult instanceof Date ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_DATE;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_DATE );","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/formula/Formula.java#L127-L163","documentation":"KettleException thrown in Formula.calcFields() when the evaluated formula returns a LibFormulaErrorValue (an error value from the Pentaho reporting formula engine) instead of a normal result. The message includes the formula, the output field, and the formula engine's error description (e.g. divide by zero, invalid argument).","triggerScenarios":"Calling data.formulas[i].evaluate() yields an error value such as #VALUE!, #DIV/0!, or an invalid reference — e.g. formula references a null field, divides by zero, or uses a function with wrong arguments.","commonSituations":"Dividing by a field that is 0 or null on some rows; passing text where a number is expected; referencing a field name with spaces without brackets; locale issues in date parsing.","solutions":["Wrap risky expressions in error-tolerant functions: IFERROR(...), ISNA(...), NVL(...) depending on the engine support.","Fix the formula's argument types/refs; read the 'error is:' tail of the message for the exact cause.","Guard division: use IF([denominator]=0;0;[numerator]/[denominator]).","Pre-convert null input fields to defaults with an upstream step or NULLIF/NVL."],"exampleFix":"// before\n\"price / quantity\"\n// after\n\"IF([quantity]=0; 0; [price]/[quantity])\"","handlingStrategy":"try-catch","validationCode":"// prefer formulas that guard inputs\n\"IF([quantity]=0; 0; [price]/[quantity])\"","typeGuard":null,"tryCatchPattern":"try { row = calcFields(row); } catch (KettleException e) { log.warn(\"Formula error on row: \" + e.getMessage()); row[f] = null; /* or send to error stream */ }","preventionTips":["Guard divisions and nulls inside the formula (IFERROR/IF/NVL)","Match argument types expected by each formula function","Preview a few rows to see per-row errors early","Read the 'error is:' suffix to pinpoint the cause"],"tags":["formula","evaluation","runtime"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}