def test_mdx_builder_with_calculated_member(self): mdx = MdxBuilder.from_cube(cube="Cube").with_member( CalculatedMember.avg( dimension="Period", hierarchy="Period", element="AVG 2016", cube="Cube", mdx_set=MdxHierarchySet.children(member=Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dim1", "Total Dim1"), Member.of("Dim2", "Total Dim2")))) \ .rows_non_empty() \ .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("DIM1", "DIM1")) \ .columns_non_empty() \ .add_member_tuple_to_columns(Member.of("Period", "AVG 2016")) \ .where("[Dim2].[Total Dim2]") \ .to_mdx() self.assertEqual( "WITH\r\n" "MEMBER [PERIOD].[PERIOD].[AVG2016] AS AVG({[PERIOD].[PERIOD].[2016].CHILDREN}," "[CUBE].([DIM1].[DIM1].[TOTALDIM1],[DIM2].[DIM2].[TOTALDIM2]))\r\n" "SELECT\r\n" "NON EMPTY {([PERIOD].[PERIOD].[AVG2016])} ON 0,\r\n" "NON EMPTY {TM1FILTERBYLEVEL({TM1SUBSETALL([DIM1].[DIM1])},0)} ON 1\r\n" "FROM [CUBE]\r\n" "WHERE ([DIM2].[DIM2].[TOTALDIM2])", mdx)
def test_calculated_member_avg(self): calculated_member = CalculatedMember.avg( dimension="Period", hierarchy="Period", element="AVG 2016", cube="Cube", mdx_set=MdxHierarchySet.children(Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dimension1", "Element1"), Member.of("Dimension2", "Element2"))) self.assertEqual( calculated_member.to_mdx(), "MEMBER [PERIOD].[PERIOD].[AVG2016] AS AVG({[PERIOD].[PERIOD].[2016].CHILDREN},[CUBE]." "([DIMENSION1].[DIMENSION1].[ELEMENT1],[DIMENSION2].[DIMENSION2].[ELEMENT2]))")
def test_calculated_member_avg(self): calculated_member = CalculatedMember.avg( dimension="Period", hierarchy="Period", element="AVG 2016", cube="Cube", mdx_set=MdxHierarchySet.children(Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dimension1", "Element1"), Member.of("Dimension2", "Element2"))) self.assertEqual( calculated_member.to_mdx(), "MEMBER [period].[period].[avg2016] AS AVG({[period].[period].[2016].CHILDREN},[cube]." "([dimension1].[dimension1].[element1],[dimension2].[dimension2].[element2]))" )
def test_mdx_build_with_multi_calculated_member(self): mdx = MdxBuilder.from_cube(cube="Cube").with_member( CalculatedMember.avg( dimension="Period", hierarchy="Period", element="AVG 2016", cube="Cube", mdx_set=MdxHierarchySet.children(member=Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dim1", "Total Dim1"), Member.of("Dim2", "Total Dim2")))) \ .with_member( CalculatedMember.sum( dimension="Period", hierarchy="Period", element="SUM 2016", cube="Cube", mdx_set=MdxHierarchySet.children(member=Member.of("Period", "2016")), mdx_tuple=MdxTuple.of(Member.of("Dim1", "Total Dim1"), Member.of("Dim2", "Total Dim2")))) \ .rows_non_empty() \ .add_hierarchy_set_to_row_axis(MdxHierarchySet.all_leaves("dim1", "dim1")) \ .columns_non_empty() \ .add_hierarchy_set_to_column_axis( MdxHierarchySet.members(members=[Member.of("Period", "AVG 2016"), Member.of("Period", "SUM 2016")])) \ .where(Member.of("Dim2", "Total Dim2")) \ .to_mdx() self.assertEqual( "WITH\r\n" "MEMBER [period].[period].[avg2016] AS AVG({[period].[period].[2016].CHILDREN}," "[cube].([dim1].[dim1].[totaldim1],[dim2].[dim2].[totaldim2]))\r\n" "MEMBER [period].[period].[sum2016] AS SUM({[period].[period].[2016].CHILDREN}," "[cube].([dim1].[dim1].[totaldim1],[dim2].[dim2].[totaldim2]))\r\n" "SELECT\r\n" "NON EMPTY {[period].[period].[avg2016],[period].[period].[sum2016]} ON 0,\r\n" "NON EMPTY {TM1FILTERBYLEVEL({TM1SUBSETALL([dim1].[dim1])},0)} ON 1\r\n" "FROM [cube]\r\n" "WHERE ([dim2].[dim2].[totaldim2])", mdx)