Forum Discussion

Sergey's avatar
Sergey
Contributor III
3 years ago

DynamicCalc : get data from siblings (or parents)

Hello,   I have a use case where I need to get data from siblings (or parents) for a dynamic calc. Entities A,B are part of the same parent EntityC. Cost1 / Entity A : 1000 Cost1 / Entity B...
  • TheJonG's avatar
    3 years ago

    You can retreive the parent of the POV Entity using the api.Member.sGetParents function. This returns a list of all parents so you can use .First to grab the first one. If base entities have multiple parents via alternate hierarchies, you need to be careful which one gets returned as it can be unpredictable which one OneStream lists first (I believe it is order in which the parents are created). Here is some script:

     

     

    Dim povEntityId As Integer = api.Pov.Entity.MemberId
    Dim povEntityDimPk As DimPk= api.Pov.Entitydim.DimPk
    Dim entityParent As List (Of Member) = api.Members.GetParents(povEntityDimPk, povEntityId, False)
    Dim firstEntityParent As Member = entityParent.First
    
    Return api.Data.GetDataCell("Divide((0.5 * A#Cost1 + A#Cost2), ( 0.5 * A#Cost1:E#" & firstEntityParent.Name & " + A#Cost2:E#" & firstEntityParent.Name & "))")

     

     

    Something to consider is that the Parent Entity may not be consolidated or aggregated to reflect recent changes to the base entities. You can use the GetEntityAggregationDataCell function to get the Cost data for the parent and it will run the parent entity aggregation at execution of the Dynamic Calc.

     

     

    Dim povEntityId As Integer = api.Pov.Entity.MemberId
    Dim povEntityDimPk As DimPk= api.Pov.Entitydim.DimPk
    Dim entityParent As List (Of Member) = api.Members.GetParents(povEntityDimPk, povEntityId, False)
    Dim firstEntityParent As Member = entityParent.First
    
    Dim parentAggCost1 As DataCell = api.Functions.GetEntityAggregationDataCell("E#" & firstEntityParent & ":A#Cost1")
    Dim parentAggCost2 As DataCell = api.Functions.GetEntityAggregationDataCell("E#" & firstEntityParent & ":A#Cost2")
    
    Return api.Data.GetDataCell("Divide((0.5 * A#Cost1 + A#Cost2), (0.5 * " & parentAggCost1.CellAmount & " + " & parentAggCost2.CellAmount & "))")