04-04-2024 01:38 PM - edited 04-04-2024 01:40 PM
A = 50% allocated to B , 40% to C, -90% to A
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
04-05-2024 12:39 PM
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)
04-08-2024 05:04 AM - edited 04-08-2024 05:07 AM
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)
04-09-2024 07:51 AM
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)
04-09-2024 05:46 PM
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.