Data Buffer
Hi - I am trying to execute the below code but it is not taking the prior month actual data. Could you please let me know what am doing wrong? It is copying only the current month.
Dim SrcDataBuffer As DataBuffer = api.Data.GetDataBufferUsingFormula("FilterMembers(V#YTD:F#EndBalInput:S#Actual:T#2026M11,[A#[BalanceSheet].Base],[U1#[Total_CostCenter].Base])")
srcdataBuffer.LogDataBuffer(api, "Results",10)
Dim Acct As String = String.Empty
Dim UD1 As String = String.Empty
Dim UD2 As String = String.Empty
Dim UD3 As String = String.Empty
Dim UD4 As String = String.Empty
Dim UD5 As String = String.Empty
Dim UD6 As String = String.Empty
Dim UD7 As String = String.Empty
Dim UD8 As String = String.Empty
Dim f As String = String.Empty
Dim Inc As String = String.Empty
Dim Org As String = String.Empty
Dim ResultDb As New DataBuffer
For Each Cell As DataBufferCell In SrcDataBuffer.DataBufferCells.Values
If Cell.CellAmount > 0 Then
'If Cell.CellStatus.IsNoData = True Then
Acct = Cell.DataBufferCellPk.GetAccountName(api)
UD1 = Cell.DataBufferCellPk.GetUD1Name(api)
UD2 = Cell.DataBufferCellPk.GetUD2Name(api)
UD3 = Cell.DataBufferCellPk.GetUD3Name(api)
UD4 = Cell.DataBufferCellPk.GetUD4Name(api)
UD5 = Cell.DataBufferCellPk.GetUD5Name(api)
UD6 = Cell.DataBufferCellPk.GetUD6Name(api)
UD7 = Cell.DataBufferCellPk.GetUD7Name(api)
UD8 = Cell.DataBufferCellPk.GetUD8Name(api)
f = Cell.DataBufferCellPk.GetFlowName(api)
Org = Cell.DataBufferCellPk.GetOriginName(api)
Inc = Cell.DataBufferCellPk.GetICName(api)
Dim ResultsCell As DataCell
ResultsCell = api.Data.GetDataCell("V#YTD:S#Actual:T#2026M10:" & "F#" & f & ":" & "I#"& Inc & ":" & "O#" & Org & ":" & "A#" & Acct & ":" & "U1#" & UD1 & ":" & "U2#" & UD2 & ":" & "U3#" & UD3 & ":" & "U4#" & UD4 & ":" & "U5#" & UD5 & ":" & "U6#" & UD6 & ":" & "U7#" & UD7 & ":" & "U8#" & UD8)
Brapi.ErrorLog.LogMessage(si, "flow" & f & "Orgin" & Org & "IC" & Inc & "Account" & Acct & "U1" & UD1 & "U2" & UD2 & "U3" & UD3 & "U4" & UD4 & "U5" & UD5 & "U6" & UD6 & "U7" & UD7 & "U8" & UD8 & ResultsCell.CellAmountAsText)
Dim ResultsCellf As New DataBufferCell(cell)
ResultsCellf.CellAmount = Cell.CellAmount + ResultsCell.CellAmount
ResultDb.SetCell(api.SI,ResultsCellf,False)
End If
Next
Dim d As ExpressionDestinationInfo = api.Data.GetExpressionDestinationInfo("V#YTD:F#EndBalInput:A#" & Acct & ":U1#" & UD1)
'Dim d As ExpressionDestinationInfo = api.Data.GetExpressionDestinationInfo("A#" & Acct & ":U1#" & UD1)
api.Data.SetDataBuffer(ResultDb,d)
That's better. Note that you don't even need to assign buffers to variables for simple math, you can just do:
Dim buf1 as DataBuffer = api.data.GetDataBufferUsingFormula(...) Dim buf2 as DataBuffer = api.data.GetDataBufferUsingFormula(...) Dim result as DataBuffer = buf1 + buf2 api.Data.SetDataBuffer(si, result, targetDestExpressionInfo)
As for the last bit: you know how, in your first code, you retrieved a buffer then looped through its cells? You can simply retrieve two buffers, then manipulate their cells directly. A buffer is effectively a dictionary, where keys are DataBufferCellPK and values are DataBufferCell; so you can get the PK of cells from buf1 and look up if there is an equivalent one with the same PK in buf2. Because this would be done in memory, rather than retrieving from db every time (which is what GetDataCell would do), it's still fast enough (even though working at the buffer level is likely to be faster).