Skip to main content

How do I calculate something?

For example, if you have two numeric inputs, "Length" and "Width," and want to display the resulting area to the user (and also want to use the area in rules, for example), first create the two numeric inputs and then proceed as follows:

Create a Calculated Number​

  • Legen Sie eine Zahleneingabe an
  • Click
    Loading...
    .
  • Check the Calculated box and click
    Loading...
    .
  • A formula editor will open. Enter the formula "Length * Width" into it. The variables will be suggested to you.
  • Click on
    Loading...
    .
  • Then click
    Loading...
    again (or
    Loading...
    , if you haven’t already).
  • A calculated variable will appear, indicated by the “=” in the input field.
info

By entering, for example, “Length,” you insert the value that the “Length” attribute currently holds. If the attribute has a key set (only possible when Developer Mode is on), this key is used in the formula instead of the attribute name.

Does the calculated value have to be displayed?​

Of course not. Simply check the Hidden box in the

Loading...
.

What calculations can I perform?​

Basically, you can only perform calculations with numbers.

All features are available as inputs; simply specify the feature name: "Length * Width"

You can also use value properties—the product data you an den Werten einer Auswahl abgelegt haben (also called attributes in formulas). If, in addition to the numeric input “Length,” there is, for example, a selection “Shape” for which you have defined a value property “Width,” then you can write: “Length * Shape.Width” (the value property must be of type Number for this to work).

You have access to basic arithmetic operations, as well as a range of mathematical functions, such as

  • sin, cos, tan
  • pow: exponentiation: pow(2,4)=2^4
  • sqrt: square root
  • round: rounding
  • ceil: next higher integer
  • floor: next lower integer

If you use product components, there are also several special functions available:

  • sum
  • sumPrevious
  • average
  • product
  • map
  • filter
  • reduce
  • instanceIndex

Specific Use Cases​

Simple Mathematical Calculations​

Area Calculation

Länge * Breite;

Volume Calculation with Attributes

Länge * Breite * Form.Höhe;

Here, Shape.Height is an attribute of the "Shape" selection value

Conditional Calculations

Material == 23 ? Fläche * 150 : Fläche * 100;

Calculations with Product Components​

Product components open up entirely new possibilities for intelligent calculations. Here are the most important use cases:

Calculate the number of parts​

Math.ceil(Länge / 2.5); // Anzahl Balken bei 2,5m Abstand

Total values of all components​

sum(map(Ausstattung.instances, (c) => c.Gewicht));

Sums the weight of all equipment components

Position Calculations for 3D Visualization​

Simple Position Based on Index

Teilelemente.Ausstattung.instanceIndex * 0.5;

Each component is offset by 50 cm

Cumulative Position Calculation with sumPrevious

One of the most common requests is the correct positioning of components based on previous elements, such as their height. The sumPrevious function makes cumulative calculations very easy:

Option 1 – Single Value:

sumPrevious(Teilelemente.Ausstattung, "Hoehe") / 100;

Automatically sums the height of all previous fixture elements and converts the result to meters.

Option 2 – With calculation:

sumPrevious(Teilelemente.Ausstattung, (e) => e.Hoehe / 100);

Sums the height of all previous elements and converts it directly to meters.

Important

The string variant ("Hoehe") only works for individual attributes—no calculations in the string!

❌ Incorrect:

sumPrevious(Elemente, "Innenbreite + Plattenstärke"); // Geht nicht!

✅ Correct:

sumPrevious(Elemente, (e) => e.Innenbreite + Plattenstärke);
Practical Tip

Create a hidden calculated field named "positionY" in the configuration using this expression. Then you can simply use Teilelemente.Ausstattung.positionY in other calculations instead of repeating the formula.

Understanding Hierarchies and Context​

The Component Hierarchy​

When working with product components, understanding the hierarchy is crucial:

Hauptprodukt
├── Teilelemente (Komponentenliste)
│ ├── Ausstattung (Unterkomponentenliste)
│ │ ├── instanceIndex (Position in der Liste)
│ │ ├── Höhe (Attribut)
│ │ └── Breite (Attribut)
│ └── andere Merkmale
└── andere Merkmale

Accessing Different Levels​

Accessing the Parent Level:

Teilelemente.Ausstattung.instanceIndex; // Index der Ausstattung

Accessing All Instances:

map(Teilelemente.Ausstattung.instances, (c) => c.Gewicht);

Accessing a Specific Instance:

Teilelemente.Ausstattung[0].Gewicht; // Erste Ausstattung

Common Errors and Solutions​

Error: “InstanceIndex does not work”​

Make sure you are at the correct hierarchy level. The instanceIndex always refers to the current component.

Error: "Division by zero"​

❌ Dangerous:

Gesamtpreis / Gesamtanzahl;

✅ Safe:

Gesamtanzahl > 0 ? Gesamtpreis / Gesamtanzahl : 0;

Available Functions in Detail​

Mathematical Functions​

  • sin, cos, tan - Trigonometric functions
  • sqrt - Square root
  • pow(basis, exponent) - Power
  • abs - Absolute value
  • min, max - Minimum/Maximum
  • clamp(wert, min, max) - Limit Value to a Range
  • round, ceil, floor - Rounding Functions

Array Functions (for Components)​

  • map(array, funktion) - Transform each element
  • filter(array, bedingung) - Filter by condition
  • reduce(array, funktion, startwert) - Reduce to a single value
  • find(array, bedingung) - Find first element
  • first(array), last(array) - First/last element
  • sum(array) - Sum of all numbers
  • sumPrevious(komponente, "attribut") or sumPrevious(komponente, e => berechnung) - Sums the values of all previous elements in a group (simplifies cumulative calculations)
  • count(array) - Number of elements
  • average(array) - Average
  • product(array) - Product of all numbers

Logical Operators​

  • && - AND
  • || - OR
  • ! - NOT
  • ==, != - Equal/Not Equal
  • <, >, <=, >= - Comparisons
  • bedingung ? wertWennWahr : wertWennFalsch - Ternary Operator

Real-World Examples for Various Industries​

Patio Roofs​

// Anzahl Pfosten basierend auf Breite
Breite <= 400 ? 2 : Math.ceil(Breite / 250);

// Anzahl Seitenelemente vorne
Pfostenanzahl -
// Position der Seitenelemente
(Gesamtbreite / (Pfostenanzahl - 1)) * instanceIndex;

Railings​

// Anzahl Füllungen
Math.floor(Gesamtlänge / Maximalbreite);

// Position der Pfosten
(Gesamtlänge / Pfostenanzahl) * instanceIndex;

Furniture/Cabinetry​

// Anzahl Regalböden
Math.floor((Höhe - 40) / Fachtiefe);

// Höhe der Regalböden
instanceIndex * Fachtiefe + 20;

Best Practices​

1. Take a Structured Approach​

  • Start with simple expressions
  • Test each step individually
  • Expand step by step

2. Reusability​

  • Use hidden calculated fields for complex intermediate results
  • Define frequently used calculations only once
  • Store numbers that appear in many formulas as Parameter, instead of writing them directly into the formulas

3. Optimizing Performance​

  • Avoid redundant calculations
  • Use intermediate results in hidden fields

4. Debugging​

If an expression doesn’t work:

  1. Check the syntax (parentheses, operators)
  2. Ensure that all variables exist
  3. Test sub-expressions individually
  4. Check the hierarchy level for components

Advanced Applications​

Dynamic Pricing​

Calculate the required quantity of a consumable item, e.g., the area:

// Fläche in qm
((Breite / 100) * Tiefe) / 100;

Create the consumable item with the price per unit, in this case, square meters (qm). When adding the item to the bill of materials, specify the calculated area as its quantity.

Validation and Constraints​

// Technische Grenzen
clamp(BenutzerEingabe, MinWert, MaxWert);

// Abhängige Werte
Typ == 100 ? BerechnetWert : ManuellerWert;

3D Positioning​

// Intelligente Verteilung
(Gesamtbreite / count(Komponenten)) * instanceIndex - Gesamtbreite / 2;

// Spiralförmige Anordnung
Math.cos(instanceIndex * 0.5) * Radius;
Important Note

The Expression Engine is very powerful, but for complex hierarchical calculations, you should proceed step by step and test each sub-calculation individually. If you have questions about implementation, please contact your implementation partner.

Conclusion​

The Expression Engine makes it possible to implement everything from simple calculations to complex hierarchical calculations. In particular, working with instanceIndex and array functions for product components opens up entirely new possibilities for intelligent product configuration.

Using the techniques shown here, you can implement dynamic price calculations, intelligent 3D positioning, and complex quantity calculations—thereby offering your customers an intuitive and powerful configuration interface.