Hi fc: MikeG's answer is quick, simple, and most likely effective based your problem statement. If you want to step into The General Problem territory, below is a custom member list function that can be used to go up/down based on a designated number of levels. I wrote this previously for going down, but was able to modify it to allow for going up as well; it should work for any dimension and would handle entities with different lengths but that still follow your 2 depth example.
This is a Finance Business Rule, of FinanceFunctionType.MemberList:
If args.MemberListArgs.MemberListName = "Level" Then
'Purpose: provides a function for returning member lists based on a "level" above/beneath the selected member
'Usage: any Cube View or Quick View where a arbitrary level of the dimension is desired
'Usage Example: A#IncomeStatement.CustomMemberList(ReplaceWithYourBrName, MemberListName=Level, Level=[2], Direction=[Up|Down])
'Get the level requested and initial member selected
Dim level As Integer
Dim validLevel As Boolean = Integer.TryParse(args.MemberListArgs.NameValuePairs.XFGetValue("Level", "0"), level)
Dim direction As String = args.MemberListArgs.NameValuePairs.XFGetValue("Direction", "Down")
'Force a valid direction
If Not ((direction = "Up") Or (direction = "Down")) Then
direction = "Down"
End If
'Member components needed for the return
Dim objMemberListHeader As New MemberListHeader(args.MemberListArgs.MemberListName)
Dim objMembers As New List(Of Member)
'Our starting point
objMembers.Add(args.MemberListArgs.TopMember)
'Check to ensure we received input
If objMembers IsNot Nothing Then
If Not validLevel Then 'user is messing with us so return where we started
Return New MemberList(objMemberListHeader, objMembers)
Else If level = 0 Then 'user wants to stay put
Return New MemberList(objMemberListHeader, objMembers)
Else If level < 0 Then 'user is messing with us so return where we started
Return New MemberList(objMemberListHeader, objMembers)
Else ' recursively loop until we hit final depth, checking for no data along the way
For nLevel = 1 To level
If objMembers IsNot Nothing Then 'check that we are not empty
Dim objMembersTemp As New List(Of Member)(objMembers) 'needed so we don't cause a recursive loop
For Each lMember As Member In objMembersTemp
objMembers.Remove(lMember) 'remove the old so don't create recursion
'Add the children/parents
If direction = "Down" Then
objMembers.AddRange(api.Members.GetChildren(args.MemberListArgs.DimPk,lMember.MemberId))
Else If direction = "Up" Then
objMembers.AddRange(api.Members.GetParents(args.MemberListArgs.DimPk, lMember.MemberId, False))
Else 'do nothing
End If
Next 'lMember
Else 'we've moved so far there are no children/parents, so return nothing
Return Nothing
End If
Next 'nLevel
'We are done looping through the members, so return the final list
Return New MemberList(objMemberListHeader, objMembers)
End If
End If
'Else something was bad with the user input so return nothing
Return Nothing
End If
You'd use it like this:
E#1010TRW.CustomMemberList(ReplaceWithYourBrName, MemberListName=Level, Level=[2], Direction=[Up])
Probably overkill for your need but another option with additional functionality.
Cheers, -db