From f2d22dbe587f463ae319312af4f3be53aeb3eb7f Mon Sep 17 00:00:00 2001 From: vish Date: Sat, 5 Aug 2023 15:05:11 +0530 Subject: [PATCH] add mdx dimension hierarchize --- mdxpy/mdx.py | 7 ++++++- test.py | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mdxpy/mdx.py b/mdxpy/mdx.py index d2bee9c..fac0f5a 100644 --- a/mdxpy/mdx.py +++ b/mdxpy/mdx.py @@ -462,7 +462,7 @@ def ancestor(member: Union[str, Member], ancestor: int) -> 'MdxHierarchySet': return AncestorHierarchySet(member, ancestor) @staticmethod - def drill_down_level(member: Union[str, Member], level) -> 'MdxHierarchySet': + def drill_down_level(member: Union[str, Member], level: int) -> 'MdxHierarchySet': if isinstance(member, str): member = Member.of(member) return DrillDownLevelHierarchySet(member, level) @@ -705,6 +705,11 @@ def __init__(self, member: Member, level): self.level = level self.member = member + if level: + self.level = level + else: + self.level = 1 + def to_mdx(self) -> str: startstring = '' endstring = '' diff --git a/test.py b/test.py index 2c53c05..59f78b0 100644 --- a/test.py +++ b/test.py @@ -279,6 +279,13 @@ def test_mdx_hierarchy_set_drill_down_level(self): "{DRILLDOWNLEVEL({[dimension].[dimension].[element]})}", hierarchy_set.to_mdx()) + hierarchy_set = MdxHierarchySet.drill_down_level(Member.of("Dimension", "Element"), level=3) + + self.assertEqual( + "{DRILLDOWNLEVEL(DRILLDOWNLEVEL(DRILLDOWNLEVEL({[dimension].[dimension].[element]})))}", + hierarchy_set.to_mdx()) + + def test_mdx_hierarchy_set_tm1_drill_down_member_all_recursive(self): hierarchy_set = MdxHierarchySet.members([Member.of("dimension", "element")]).tm1_drill_down_member( recursive=True)