Forum Discussion

Marco's avatar
Marco
Contributor II
2 months ago

How do I clean a scenario before copying data from another scenario? in the member formula.

Hi Everyone.
I want to copy the information from one scenario to another. Currently, I’m using the member formula of the target scenario to transfer the data. However, I first apply a calculate to set the values to zero, followed by a clecarcalculateddata to properly remove the existing information. The issue is that after this step, the copy process doesn’t execute, and the scenario remains with zero values. My code is as follows:

api.Data.calculate("S#FORECAST_" & monthNumber & "_AT_CY_BUDGET_RATE = 0*(S#FORECAST_" & monthNumber & "_AT_CY_BUDGET_RATE)",True)
api.Data.ClearCalculatedData("S#FORECAST_" & monthNumber & "_AT_CY_BUDGET_RATE",True,True,True,True)							

Dim destinationInfo As ExpressionDestinationInfo = api.Data.GetExpressionDestinationInfo("S#FORECAST_" & monthNumber & "_AT_CY_BUDGET_RATE")

'' Create new Databuffer for the results
Dim resultDataBuffer As New DataBuffer

'Base Entity at Local
If Not api.Entity.HasChildren And api.Cons.IsLocalCurrencyForEntity() Then
	BRapi.ErrorLog.LogMessage(si,"Validate 1")
	' Get Databuffer from the account and scenario
    Dim sourceDataBuffer As DataBuffer = api.data.GetDataBufferUsingFormula("RemoveZeros(FilterMembers(S#[Forecast " & TimeName & "],[A#Root.Base]))", , False)
    ' Verificar si hay celdas con datos
    If sourceDataBuffer.DataBufferCells.Count > 0 Then
		BRapi.ErrorLog.LogMessage(si,"Validate 2")
        For Each sourceCell As DataBufferCell In sourceDataBuffer.DataBufferCells.Values

            If (Not sourceCell.CellStatus.IsNoData) And (sourceCell.CellAmount <> 0.0) Then
				BRapi.ErrorLog.LogMessage(si,"Validate 3")
                Dim resultCell As New DataBufferCell(sourceCell)

                resultCell.DataBufferCellPk.OriginId = DimConstants.Import

                resultDataBuffer.SetCell(si, resultCell, True)

            End If
        Next

        api.Data.SetDataBuffer(resultDataBuffer, destinationInfo,,,,,,,,,,,,,False)

    End If
End If

I would appreciate your help in understanding why the values are not being copied. The process is executed when I consolidate the information.

5 Replies

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    You can clear a scenario (completely, all nodata) by running the Reset Scenario data management step, then with another data managment step, copy the data.  Perhaps a bit easier to build and maintain than similar calculations in code. 
    Also note, I wouldn't perform clear then copy in a member formula.  That could cause problems and the next guy will never be able to find it.

     

  • Henning's avatar
    Henning
    Valued Contributor II

    Hi, as per default, each data unit gets cleared during a calculation operation (e.g. during a consolidation). This only does not apply if the corresponding scenario setting is set to False. However, in all my years in the OS world, I have never seen it being set to False.

     

    Your calculation really just seems to pull data without a filter one from scenario to another. Just use a standard api.data.calculate("S#destinationScenario = removezeros(S#sourceScenario)"). On local currency and base entities and other things you might want.

    Use a scenario member formula for that to make sure this gets executed first. 

    My high-level guess as to why yours does not work is that the member formula executes during a calculation of the source scenario. Keep in mind, calculations in OneStream are "pull", i.e. you cannot push data from your source scenario to your destination scenario. The calculation has to be executed from the destination scenario in order to pull the data from the source scenario.

    • Marco's avatar
      Marco
      Contributor II

      So, are you recommending that I use a standard calculate function without all the additional logic? I had disabled the 'Clear Calculated Data during calc' option, but it didn’t help much, as the data was not being cleared when running the formula.

       

      • Henning's avatar
        Henning
        Valued Contributor II

        Yes, from what I see, you do not need any additional logic such as data buffers. Maybe something to clear the durable data as rhankey​ suggested. 

        You can use the scenario member formulas if you want the seeding to run during every single consolidation of the forecast scenario, or use a custom calculate to trigger the seeding e.g. via a workflow process step if the seeding should only happen on demand. There are more options, but these two approaches are probably the most common ones.

        Also, try to use Api instead of BRApi where possible for better performance. E.g. your TimeName string I assume can be set with Api.Pov.Time.Name.

        For everything else, more detailed requirements are necessary.