Skip to main content

Data Buffers

Data Buffers are an object complete with its own properties and methods enabling simple to complex calculations for data or a subset “slice” of data within a Data Unit. Storing data temporarily in memory, data buffers provide efficiency and performant handling of data during processing of calculations. Compared to Dynamic Calc formulas implemented with api.Data.GetDataCell that calculate on a single data cell, this object operates across various non data unit dimensions and is multi data cell.

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.CSharp;
using OneStream.Finance.Database;
using OneStream.Finance.Engine;
using OneStream.Shared.Common;
using OneStream.Shared.Database;
using OneStream.Shared.Engine;
using OneStream.Shared.Wcf;
using OneStream.Stage.Database;
using OneStream.Stage.Engine;

namespace OneStream.BusinessRule.Finance.DFM_CustomCalcs
{
public partial class MainClass
{
// ------------------------------------------------------------------------------------------------------------
// Reference Code: DFM_CustomCalcs
//
// Description: A subset of DFM_CustomCalcs converted to C#
//
// Created By: OneStream Software
// Date Created: 06-05-2025
// ------------------------------------------------------------------------------------------------------------
public object Main(SessionInfo si, BRGlobals globals, FinanceRulesApi api, FinanceRulesArgs args)
{
try
{
switch (api.FunctionType)
{
case var @case when @case == FinanceFunctionType.CustomCalculate:
{
// ---------------------------------------------------------------------------------------------------------------------------
// EXPRESSION LIST CALCS
// ---------------------------------------------------------------------------------------------------------------------------
if (args.CustomCalculateArgs.FunctionName.XFEqualsIgnoreCase("ExecuteSeeding"))
{
// Seeding rule from the Actual scenario to Fcst_M# scenarios
// Seeding is based on the number of no Input Periods In the Scenario Properties for the Fcst_M# scenarios
// Assumption
// The source And target have a Workflow Tracking Frequency Of Monthly
// Soucre scenario name is Actual
// Assumptions based on Data Entry 123 (D123) configuration for target members
// Cube is FinRpg
// Entity is the selection from the D123 Interface
// Parent is None
// Consolidation member Is Local
// Scenario is |WFScenario|, Workflow POV scenario
// Time is |WFYear|, Workflwo POV time
// All other dimensions are set to None

// Declare a variable and set the number of No Input Periods based on the Fcst_M# scenario
int curFcstMonth = api.Scenario.GetWorkflowNumNoInputTimePeriods();

// If the the nubmer of No Input Periods is Not 0 executue; otherwise, nothing to do as Actuals are not seeded
if (!(curFcstMonth == 0))
{
// Only run when the Workflow POV Scenario name contains FCST, an entity is a base entity and the consolidation member is Local
if (api.Pov.Scenario.Name.XFContainsIgnoreCase("Fcst") && !api.Entity.HasChildren() && api.Cons.IsLocalCurrencyForEntity())
{
// Clear previously calculated, translated, consolidated and durable calc data for all time periods
api.Data.ClearCalculatedData(true, true, true, true);

// Declare and set variables
// Set the source scenario name to the value in Text1 of the POV Scenario
var strSrcScenarioName = api.Scenario.Text(1);
// Get the month number from the current time period being processed and set the variable
int curMonthNumber = TimeDimHelper.GetSubComponentsFromId(api.Pov.Time.MemberId).Month;
// Get the Workflow POV Scenario name and set the variable
string curScenarioName = api.Pov.Scenario.Name;

// Only perform the seeding if the variable, strSrcScenarioName has a value and the current month is less than or equal to the forecast month
if (string.IsNullOrWhiteSpace(strSrcScenarioName) == false && curMonthNumber <= curFcstMonth)
{
// Declare a DataBuffer and store data from the Actual scenario in the Data Buffer
DataBuffer actualDataBuffer = api.Data.GetDataBufferUsingFormula($"RemoveZeros(S#{strSrcScenarioName})");
// Declare a DataBuffer and convert the Data Buffer "actualDataBuffer" for extended members
DataBuffer convertedActualDataBuffer = api.Data.ConvertDataBufferExtendedMembers(api.Pov.Cube.Name, strSrcScenarioName, actualDataBuffer);
// Store the converted actual data buffer in a Data Buffer variable
api.Data.FormulaVariables.SetDataBufferVariable("ConvertedActuals", convertedActualDataBuffer, true);
// Write the Data Buffer variable in the Workflow Profile scenario as durable calc data
api.Data.Calculate("S#" + curScenarioName + " = $ConvertedActuals", true);
}
}
}
}

break;
}
}

return null;
}

catch (Exception ex)
{
throw ErrorHandler.LogWrite(si, new XFException(si, ex));
}
}
}
}

Was this page helpful?