Forum Discussion

Marco's avatar
Marco
Contributor II
4 months ago

Allocation: charge from one entity to another

Hi Everyone.

What I want to achieve is a method for performing an allocation where a charge is made from one entity to another, or even perhaps just a different department within the same entity. I have been reviewing examples, but I have not seen one where this transfer is made and the amount in the source entity is adjusted to reflect the charge. Therefore, I would appreciate your assistance in implementing this in a Business Rule (BR) to accomplish something similar to the example shown in the image and the BR that I reviewed.

Dim sourcePov As String = "E#A:O#Import:F#EndBal_Load:A#100001:UD5#ADJ"
api.Data.FormulaVariables.SetDataBufferVariable("source", sourceBuf, False)
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)
api.data.calculate(sourcePov & " = 0 * $source")
api.data.clearcalculateddata(sourcePov, True, True)

 

  • TheJonG's avatar
    TheJonG
    Contributor III

    Hi Marco - it is not possible to write an api.Data.Calculate the way you have it with Entity defined on the destination script. You can only write to the current Entity being processed which would be defined in the Data Management step. The best way to do this would be to execute a CustomCalculateRule or DataManagementSequence and passing in the Target entities via the parameter dictionary. Below is an example of this. The initial rule would be ran on the Source Entity to write the Allocation Out and then the target entities are looped over and a Custom Calculate rule is executed on those entities to write the Allocation In. 

    Else If args.CustomCalculateArgs.FunctionName.XFEqualsIgnoreCase("AllocationAcrossEntities") Then
    	'Calculate the Allocated Out member for ACME (Source Entity)
    	api.Data.Calculate("A#Rent:F#AllocatedOut:I#None:O#Import = A#Rent:I#None:O#Top:F#EndBalLoad",True)
    	
            'Get a list of target entities to write allocation data to
    	Dim entityList As List(Of Member) = api.Members.GetBaseMembers(api.Pov.EntityDim.DimPk,api.Members.GetMemberId(dimtypeid.Entity,"ACMEGroup"))
    
    		'Loop on all the data unit dimensions to trigger the custom calculate
    		For Each entity As Member In entityList
    		If Not entity.Name.Equals("ACME") Then
    			Dim brParamDict As New Dictionary(Of String, String) From {{"Cube", api.Pov.Cube.name},
    			                        {"Entity", entity.Name},
    			                        {"Consolidation", "Local"},
    			                        {"Scenario", api.Pov.Scenario.Name},
    			                        {"Time", timedimhelper.GetYearFromId(api.Pov.Time.MemberId)},
    			                        {"View", "YTD"}}
    			'Trigger custom calculate
    			BRApi.Finance.Calculate.ExecuteCustomCalculateBusinessRule(si, "Chapter8Examples", "RentAllocation2", brParamDict, CustomCalculateTimeType.AllInYear)
    		End If        
    		Next entity
    
    Else If args.CustomCalculateArgs.FunctionName.XFEqualsIgnoreCase("RentAllocation") Then
    
    	'This function is referenced in the previous function 
    	If ((Not api.Entity.HasChildren()) And (api.Cons.IsLocalCurrencyforEntity())) Then
    		api.Data.ClearCalculatedData(True,True,True,True,"A#Rent")
    		Dim totalSquareFootage As Decimal = api.Functions.GetEntityAggregationDataCell("E#ACMEGroup:O#Top:I#Top:F#EndBalLoad:A#SquareFootage:" & _
    																						"U1#None:U2#None:U3#None:U4#None:U5#None:U6#None:U7#None:U8#None").CellAmount
    		
    		api.Data.Calculate("A#Rent:I#None:O#Import = RemoveZeros(MultiplyUnbalanced(C#Local:E#ACME:A#Rent:O#Top:I#Top, " & _
    		"Divide(A#Squarefootage:O#Top:I#Top:U1#None:U2#None, " & totalSquareFootage & "),U1#None:U2#None))",True)
    
    	End If	

     

    • Marco's avatar
      Marco
      Contributor II

      Hi Jon.

      What needs to be done in that business rule in order to carry out this process?

      • TheJonG's avatar
        TheJonG
        Contributor III

        Hi Marco - I am not sure what you are asking. The script I sent is an example of using the BRApi.Finance.Calculate.ExecuteCustomCalculateBusinessRule and can be modified to fit your exact application and use case.