Ioana
2 years agoNew Contributor III
Redirect Data Buffer result
Hello,
I am trying to adjust the code below to handle the following situation:
The client loaded data for Test Rate and Test Count on UD1 "ID".
The data buffers defined for prior month (TotDirCOGSDataBuffer and DirCOGSDataBuffer) do not have any values for UD1 "ID". The client wants to do the calculation for UD1 "ID" as follows: take the prior month data from another UD1 member, multiply with the Test Rate and Test Count for UD1 "ID" and place the results on UD1 "ID".
How I can accommodate this change, considering this will happen also in the future when they need to perform a calculation on a UD1 member which does not have values in prior months?
'api.Data.ClearCalculatedData(True,True,True,True,"U7#DirCOGS_Calc")
api.Data.ClearCalculatedData(True,True,True,True,,,,,,,,,,,"U7#DirCOGS_Calc",)
'Create a result data buffer and destination info to add the cells to later
Dim resultDataBuffer6 As DataBuffer = New DataBuffer()
Dim destinationInfo6 As ExpressionDestinationInfo = api.Data.GetExpressionDestinationInfo("F#EndBalLoad:O#Import:I#None" & _
":U5#None:U6#None:U7#DirCOGS_Calc:U8#None")
'Get total Direct COGS to use in Calc
' Dim TotDirCOGSDataBuffer As DataBuffer = api.Data.GetDataBufferUsingFormula("FilterMembers(RemoveZeros(A#Dir_COGS:F#Top:O#Top:T#POVPrior1:I#Top" & _
' ":U5#None:U6#None:U7#Top:U8#Top),U2#101)")
Dim TotDirCOGSDataBuffer As DataBuffer = api.Data.GetDataBufferUsingFormula("RemoveZeros(FilterMembers(A#Dir_COGS:F#Top:O#Top:T#POVPrior1:I#Top" & _
":U5#None:U6#None:U7#Top:U8#Top,U2#101))")
For Each TotDirCOGSSourceCell As DataBufferCell In TotDirCOGSDataBuffer.DataBufferCells.Values
Dim UD1 As String = TotDirCOGSSourceCell.GetUD1Name(api).ToString 'Brand
Dim TotDirCOGSAmount As Decimal = TotDirCOGSSourceCell.CellAmount
'Declare source data buffers for Run Rate
' Dim DirCOGSDataBuffer As DataBuffer = api.Data.GetDataBufferUsingFormula("FilterMembers(RemoveZeros(F#Top:O#Top:T#POVPrior1:I#Top" & _
' ":U5#None:U6#None:U7#Top:U8#Top),A#Dir_COGS.Base,U1#" & UD1 & ",U2#101)")
Dim DirCOGSDataBuffer As DataBuffer = api.Data.GetDataBufferUsingFormula("RemoveZeros(FilterMembers(F#Top:O#Top:T#POVPrior1:I#Top" & _
":U5#None:U6#None:U7#Top:U8#Top,A#Dir_COGS.Base,U1#" & UD1 & ",U2#101))")
For Each DirCOGSSourceCell As DataBufferCell In DirCOGSDataBuffer.DataBufferCells.Values
' Dim UD2 As String = DirCOGSSourceCell.GetUD2Name(api).ToString ' Department
Dim DirCOGSAmount As Decimal = DirCOGSSourceCell.CellAmount
Dim resultCell As New DataBufferCell(DirCOGSSourceCell)
'Declare variables for TestCount
Dim TestCountCurr As Decimal = api.data.getdatacell("A#TestCount:T#" & POVPERIOD & ":V#Periodic:F#Top:O#Top:I#Top:U1#" & UD1 & ":U2#Top:U3#Top:U4#Top:U5#None:U6#None:U7#Top:U8#Top").CellAmount
'Declare variables Test Rate
Dim TestRate As Decimal = api.data.getdatacell("A#TestRate:T#" & sPOVYEAR & Quarter &":V#Periodic:F#EndBalLoad:O#Forms:I#None:U1#" & UD1 & ":U2#None:U3#None:U4#None:U5#None:U6#None:U7#None:U8#None").CellAmount
' If UD2 = "101" Then
resultCell.CellAmount = DirCOGSAmount/TotDirCOGSAmount * TestCountCurr * TestRate
' End If
resultDataBuffer6.SetCell(si, resultCell)
Next
Next
api.Data.SetDataBuffer(resultDataBuffer6,destinationInfo6)