Skip to main content

How do I have something calculated?

For example, if you have two numerical 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), then first create the two number inputs and then proceed as follows then proceed as follows:

Create calculated number

  • Legen Sie eine Zahleneingabe an
  • Click on
    Loading...
    .
  • Check the Calculated box and click on
    Loading...
    .
  • A formula editor opens. Now enter the formula "Length * Width". The variables are suggested to you.
  • Click on
    Loading...
    .
  • And again on
    Loading...
    (or
    Loading...
    , if not already done).
  • A calculated variable appears, recognizable by the "=" in the input field.

Does the calculated value have to be displayed?

Of course not. Simply activate the Hidden checkbox in the

Loading...
.

Which calculations can I perform?

Basically, you can only calculate with numbers.

All characteristics are available as input, simply by entering the name of the characteristic: "Length * Width"

You can also use attributes. If, in addition to the numerical input "Length", there is a selection "Shape", for example, for whose values you enter a Attribut "Breite" definiert haben, then you can write: "Length * Shape.width" (of course, the attribute must then have the type number).

The basic arithmetic operations are available to you, as well as a range of mathematical functions, such as

  • sin, cos, tan
  • pow: Power: pow(2,4)=2^4
  • sqrt: Root
  • round: Rounding
  • ceil: Next larger integer
  • floor: Next smaller integer

If you use product components, there are some special functions for this:

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

Concrete use cases

Simple mathematical calculations

Area calculation

Länge * Breite;

Volume calculation with attributes

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

shape.height is an attribute of the selection value "Shape"_

Conditional calculations

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

Calculations with product components

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

Calculating the number of components

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

Total values of all components

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

Summarizes the weight of all equipment components

Position calculations for 3D display

Simple position based on index

Teilelemente.Ausstattung.instanceIndex * 0.5;

Each equipment is offset by 50cm

Extended cumulative position calculation

One of the most frequent requests is the correct positioning of components based on their height, for example:

sum(
map(
filter(
Teilelemente.Ausstattung.instances,
(c) => c.instanceIndex < Teilelemente.Ausstattung.instanceIndex
),
(c) => c.Hoehe / 100
)
);

What happens here in detail:

  1. Teilelemente.Ausstattung.instances - All instances of the equipment
  2. filter(..., c => c.instanceIndex < Teilelemente.Ausstattung.instanceIndex) - Only the instances BEFORE the current one
  3. map(..., c => c.Hoehe/100) - Convert the height of each instance into meters
  4. sum(...) - Add everything for the cumulative height
Practical tip

Create a hidden calculated field "positionX" in the equipment with this expression. Then you can simply use Teilelemente.Ausstattung.positionX in other calculations instead of repeating the complex 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

Access to different levels

Access to higher level:

Teilelemente.Ausstattung.instanceIndex; // Index der Ausstattung

Access to all instances:

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

Access to specific instance:

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

Common errors and solutions

Error: "InstanceIndex does not work"

Make sure that 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 in range
  • round, ceil, floor - Rounding functions

Array functions (for components)

  • map(array, funktion) - Transformation of each element
  • filter(array, bedingung) - Filter by condition
  • reduce(array, funktion, startwert) - Reduction to one value
  • find(array, bedingung) - Find first element
  • first(array), last(array) - First/last element
  • sum(array) - Sum of all numbers
  • count(array) - Number of elements
  • average(array) - Average
  • product(array) - Product of all numbers

Logical operators

  • && - AND
  • || - OR
  • ! - NOT
  • ==, != - equal/unequal
  • <, >, <=, >= - Comparisons
  • bedingung ? wertWennWahr : wertWennFalsch - Ternary operator

Practical examples for different 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/Cabinets

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

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

Best Practices

1. proceed in a structured manner

  • 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

3. optimize performance

  • Avoid redundant calculations
  • Use intermediate results in hidden fields

4. debugging

If an expression does not work:

  1. Check the syntax (brackets, operators)
  2. Make sure 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, e.g. the area:

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

Create the consumable item with the price for the unit, in this case sqm. When adding the article to the parts list, enter the calculated _area** as its quantity 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 any 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 completely new possibilities for intelligent product configuration.

With the techniques shown here, you can realize dynamic price calculations, intelligent 3D positioning and complex quantity calculations - and thus offer your customers an intuitive and powerful configuration interface.