03-17-2024 01:34 PM - last edited on 03-18-2024 06:40 AM by JackLacava
Api.Data.Calculate(“A#28100=A#69000”)
What is wrong with writing a calculation like this? Tips.
A#28100 might contain thousands of cells.
Calculation MAY work but will damage performance.
Defining more dimensions reduces the number of cells that need to be processed.
A#28100 = 10 Flow x 1 IC(None) x 3 Origin x 10 UD1 x 20 UD2 x UD3 x UD4 etc
Defining more Dimensions reduces the number of cells OneStream has to process.
Write the rule as follows:
To learn more see GES - Level 2: Financial Model Rules Course
Level2-Rules.pdf (hubspotusercontent30.net)
03-18-2024 11:23 AM - edited 03-18-2024 11:58 AM
Hi @cbriscoe great reminder!
While refactoring, consider also using short-circuit operators when optimizing code for efficiency. In this case, if HasChildren() evaluates true, there's no need to check if isLocalCurrencyForEntity is also true, 'AndAlso' provides the short-circuit to skip the unnecessary second evaluation.:
If Not api.Entity.HasChildren() AndAlso api.Cons.IsLocalCurrencyForEntity() Then
api.Data.Calculate("A#28100:F#None:I#None = RemoveZeros(A#69000:F#EndBal_Plan:I#Top)", "O#Top.base", "U2#TopProducts.base")
End If
When setting these up, if you know which part of the If will most likely evaluate false, put that at the far left of the If statement where it will get looked at first by the IF. E.g. if isLocalCurrencyForEntity is false more than HasChildren, evaluate it first (furthest left).
Personally I'm willing to give up a tiny bit of performance for increasing readability:
Dim isBaseEntity as Boolean = Not api.Entity.HasChildren()
Dim isLocalCurrency as Boolean = api.Cons.IsLocalCurrencyForEntity()
If isBaseEntity AndAlso isLocalCurrency Then
api.Data.Calculate("A#28100:F#None:I#None = RemoveZeros(A#69000:F#EndBal_Plan:I#Top)", "O#Top.base", "U2#TopProducts.base")
End If