Skip to content

Commit

Permalink
updated hierarchy drilldown with level
Browse files Browse the repository at this point in the history
  • Loading branch information
vishn90 authored and MariusWirtz committed Aug 7, 2023
1 parent 806597d commit fd5e5fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions mdxpy/mdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ def ancestor(member: Union[str, Member], ancestor: int) -> 'MdxHierarchySet':
return AncestorHierarchySet(member, ancestor)

@staticmethod
def drill_down_level(member: Union[str, Member]) -> 'MdxHierarchySet':
def drill_down_level(member: Union[str, Member], level) -> 'MdxHierarchySet':
if isinstance(member, str):
member = Member.of(member)
return DrillDownLevelHierarchySet(member)
return DrillDownLevelHierarchySet(member, level)

@staticmethod
def descendants(member: Union[str, Member], level_or_depth: Union[MdxLevelExpression, int] = None,
Expand Down Expand Up @@ -700,12 +700,19 @@ def to_mdx(self) -> str:

class DrillDownLevelHierarchySet(MdxHierarchySet):

def __init__(self, member: Member):
def __init__(self, member: Member, level):
super(DrillDownLevelHierarchySet, self).__init__(member.dimension, member.hierarchy)
self.level = level
self.member = member

def to_mdx(self) -> str:
return f"{{DRILLDOWNLEVEL({{{self.member.unique_name}}})}}"
startstring = ''
endstring = ''
for _ in range(self.level):
startstring += 'DRILLDOWNLEVEL('
endstring += ')'

return f"{{{startstring}{{{self.member.unique_name}}}{endstring}}}"


class DescendantsHierarchySet(MdxHierarchySet):
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def test_mdx_hierarchy_set_ancestor(self):
hierarchy_set.to_mdx())

def test_mdx_hierarchy_set_drill_down_level(self):
hierarchy_set = MdxHierarchySet.drill_down_level(Member.of("Dimension", "Element"))
hierarchy_set = MdxHierarchySet.drill_down_level(Member.of("Dimension", "Element"), level=1)

self.assertEqual(
"{DRILLDOWNLEVEL({[dimension].[dimension].[element]})}",
Expand Down

0 comments on commit fd5e5fb

Please sign in to comment.