The OneStream Community is temporarily frozen until June 29th due to the ongoing maintenance. Please read the blog post here to learn more.
Forum Discussion
AndreaF
2 years agoContributor III
Using a variable in the calculate string formula
Hi, I am in a custom business rule. I have a calculate formula like the following one, which works fine: api.Data.Calculate("A#Sales1 = A#Sales2 + 50”) Now let say I want to declare a varia...
- 2 years ago
The safest approach is this:
Api.Data.FormulaVariables.SetDecimalVariable("Growth", 50)
API.data.Calculate("A#Sales1 = A#Sales2 + $Growth”)
This approach avoids possible issues with converting numbers to string - when the user executing it has a different Culture, or when decimals get truncated (hence losing precision). There is a blog post discussing it as part of internationalising an application.
RobbSalzmann
2 years agoValued Contributor II
Here you go:
Dim Growth As Decimal = 50
api.Data.Calculate($"A#Sales1 = A#Sales2 + {Growth}”)- AndreaF2 years agoContributor III
This formula gives me the following error:
"Unable to execute Business Rule 'Plan'. Invalid calculation script. Unexpected text. {Growth}."
- Big_Rick_CPM2 years agoContributor
The method Robb mentions is using string interpolation. The error message you sent to me sounds like you are missing the dollar sign ($) before the literal string that tells the complier it is an interpolated string.
Related Content
- 2 years ago
- 3 years ago