11-22-2021 06:12 AM - last edited on 05-02-2023 10:43 AM by JackLacava
There are certain calculations are specific to some entities in the hierarchy so want to add if condition to check entity names and then execute the code.
Couldn't find any api which returns Entity name.
Regards,
Yashwant
Solved! Go to Solution.
11-22-2021 06:19 AM
Hi Yashwant,
Api.pov.Entity.Name should do the trick.
11-22-2021 06:23 AM - edited 11-22-2021 06:23 AM
11-22-2021 06:41 AM - edited 11-22-2021 06:42 AM
Yes, you can use api.Members.IsBase - see below.
'Get DimPk for POV Entity Dimension
Dim objDimPk As DimPk = api.Pov.EntityDim.DimPk
'Get Member ID for POV Entity Member
Dim entityID As Integer = api.Pov.Entity.MemberId
'Get Member ID for selected ancestor
Dim ancestorID As Integer = api.Members.GetMember(DimType.Entity.Id,"GroupGBP").MemberId
'Run only on base entities of selected ancestor
If api.Members.IsBase(objDimPk, ancestorID, entityID) Then
api.data.calculate("A#Check = A#Check1")
End If
Lee
11-22-2021 08:14 AM - edited 11-22-2021 08:30 AM
There is also a api.pov.parent, but it only works for relationship related consolidation members like elimination or share.
Alternative to Lee's solution, you can also work with api.members.getparents(...) or api.members.getchildren(..) and check if the requested parent/member is in the result list, this might be helpfull if you have to repeat the check or if you like to test more than one parent.
somthing like this:
Dim parentList As list(Of member) = api.members.getParents(api.Pov.EntityDim.DimPk, api.pov.entity.memberid, False)
If Not parentList.Find(Function(x) x.Name="ParentName") Is Nothing
End If
Dim parentID As Integer = api.Members.GetMemberId(dimtypeid.Entity, "ParentName")
Dim childrenList As list(Of member) = api.members.GetChildren(api.Pov.EntityDim.DimPk, parentID)
If Not childrenList.Find(Function(x) x.MemberId=api.pov.Entity.MemberId) Is Nothing
End If
You should also consider, to use a text attribute to identify the entities for the calculation: api.Entity.Text(1) = "Calc".
11-22-2021 06:19 AM
Hi Yashwant,
Api.pov.Entity.Name should do the trick.
11-22-2021 06:23 AM - edited 11-22-2021 06:23 AM
Hi Yashwant,
api.Pov.Entity.Name
Lee
11-22-2021 06:35 AM
Thanks a lot.. Yes, its working.
Is there any way to loop through Parent its children to avoid adding many if conditions.
Thank You
Regards,
Yashwant
11-22-2021 06:41 AM - edited 11-22-2021 06:42 AM
Yes, you can use api.Members.IsBase - see below.
'Get DimPk for POV Entity Dimension
Dim objDimPk As DimPk = api.Pov.EntityDim.DimPk
'Get Member ID for POV Entity Member
Dim entityID As Integer = api.Pov.Entity.MemberId
'Get Member ID for selected ancestor
Dim ancestorID As Integer = api.Members.GetMember(DimType.Entity.Id,"GroupGBP").MemberId
'Run only on base entities of selected ancestor
If api.Members.IsBase(objDimPk, ancestorID, entityID) Then
api.data.calculate("A#Check = A#Check1")
End If
Lee
11-22-2021 08:14 AM - edited 11-22-2021 08:30 AM
There is also a api.pov.parent, but it only works for relationship related consolidation members like elimination or share.
Alternative to Lee's solution, you can also work with api.members.getparents(...) or api.members.getchildren(..) and check if the requested parent/member is in the result list, this might be helpfull if you have to repeat the check or if you like to test more than one parent.
somthing like this:
Dim parentList As list(Of member) = api.members.getParents(api.Pov.EntityDim.DimPk, api.pov.entity.memberid, False)
If Not parentList.Find(Function(x) x.Name="ParentName") Is Nothing
End If
Dim parentID As Integer = api.Members.GetMemberId(dimtypeid.Entity, "ParentName")
Dim childrenList As list(Of member) = api.members.GetChildren(api.Pov.EntityDim.DimPk, parentID)
If Not childrenList.Find(Function(x) x.MemberId=api.pov.Entity.MemberId) Is Nothing
End If
You should also consider, to use a text attribute to identify the entities for the calculation: api.Entity.Text(1) = "Calc".
11-26-2021 04:19 AM
Thank You.
Earlier I had though of using Text1 field for this purpose but saw api.Entity.Text however was not aware of retrieving Text1 contents.
api.Entity.Text(1) = "Calc" -- This is very valuable information.
12-01-2021 05:54 AM
I agree with the preference to use Text attributes and try to stay away from hard-coding entity/member names where possible. But also PLEASE be careful about upper/lowercase string comparisons, and try to use the XFEqualsIgnoreCase where possible. I've seen a number of incidents where conditions are not being met because the upper/lower case is not matching.