Avoid circular dependency with formulas
Question
> I have two characteristics (special length and special stroke). Both are dependent on each other and could be calculated using a formula. When I enter the formulas in both characteristics, I get an error message. > > Example: The value of the special stroke is calculated by entering "special length - 180". Conversely, the special length is "special stroke + 180". However, it should remain open whether the user enters a stroke or a length.
Answer
For circular dependencies (A is calculated from B, B is calculated from A), you must provide the user with a decision. The user chooses which value he wants to enter - the other characteristic is then calculated.
Solution approach
-
Create selection characteristic: "Would you like to enter special length or special stroke?" with the values "Special length" and "Special stroke"
-
Hide input fields: Depending on the selection, the input field should be hidden per action rule that is not required
-
Create calculated field: A hidden berechnetes Merkmal "Actual special length" with the following formula:
variable("Möchten Sie Sonderlänge oder Sonderhub eingeben?").value == 1 ? Sonderlänge : Sonderhub + 180
Create attribute for the selection
For the formula to work, you must create aa attribute (value property) for the selection:
- Open the Values of the characteristic "Do you want to enter special length or special stroke?"
- Click on "New column "
- Name the column "value " and select "Number " as the type
- Click on "Create "
- Assign a 1 for the value "Special length" and a 0 for "Special stroke"
variable("...")- Characteristics with spaces in the name are packed into thevariable()functionMerkmal.Attribut- Thevariable("...").valuenotation is used to access the "value" attribute of the selectiona ? b : c- The ternary operator: Ifais true,bis delivered, otherwisec
Result
- If the user selects "Special length", they enter the length directly → the "Actual special length" field accepts the value
- If the user selects "Special stroke", they enter the stroke → the "Actual special length" field automatically calculates
Sonderhub + 180
Further information
- Wie lasse ich etwas berechnen? - Basics of calculated features
- Attribute/Wert-Eigenschaften anlegen - Additional information on selection values
- Merkmale ausblenden - Show and hide characteristics according to rules
Related topics
- Conditional calculations
- Ternary operator in formulas
- Hidden calculated fields