Allocation

OS_Pizza
Contributor III

A = 50% allocated to B , 40% to C,  -90% to A

OS_Pizza_0-1712252155649.png

What will be the best approach to allocate data between entities?  Also, If you have a code snippet for data buffer that will be helpful.

1. Data Buffer

2. ADC

 

4 REPLIES 4

osdevadmin
New Contributor III

attempted this, but unsure if my OFFSET is correct:

api.Data.Calculate("E#B:O#Forms:A#100001:UD5#ADJ = 0.5 *(E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ",False) 
api.Data.Calculate("E#C:O#Forms:A#100001:UD5#ADJ = 0.4 *(E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ",False)
api.Data.Calculate("E#C:O#Forms:A#100001:UD5#ADJ = -0.9 *(E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ",False)

'OFFSET
api.Data.Calculate("E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ = E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ + (-1 *(E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ)",False)

 

Close, but your code has a problem: it retrieves source data multiple times, which might impact performance.

A better approach is to get it in a buffer, assign it to a variable, then reuse the variable. In this way, we pull data in memory from the database only once.

' retrieve source data and assign to variable, so we do it only once
Dim sourcePov As String = "E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ"
Dim sourceBuf As DataBuffer = api.Data.GetDataBufferUsingFormula("RemoveNoData(" & sourcePov & ")")
api.Data.FormulaVariables.SetDataBufferVariable("source", sourceBuf, False)
' do your calculations. 
api.Data.Calculate("E#B:O#Forms:A#100001:UD5#ADJ:F#SomeFlow = $source *  0.5", False) 
api.Data.Calculate("E#C:O#Forms:A#100001:UD5#ADJ:F#SomeFlow = $source *  0.4", False) 
api.Data.Calculate("E#C:O#Forms:A#100001:UD5#ADJ:F#SomeFlow = $source * -0.9", False) 
' optional: delete source data by overwriting intersections with calculated data which is then cleared
api.data.calculate(sourcePov & " = 0 * $source")
api.data.clearcalculateddata(sourcePov, True, True)

 

osdevadmin
New Contributor III

thanks @JackLacava ! hope OP finds this useful, i have one query in above code is writing Line 11 optional as we are sort of clearing sourcePov in line 10 and if we don't write line 10, then will line 11 still work?

api.data.calculate(sourcePov & " = 0 * $source")
api.data.clearcalculateddata(sourcePov, True, True)

 

No, it's optional in the sense that not everyone might need to clear the source intersections. You either use both lines, or none of them.