Back to snippets

mdxpy_query_builder_with_rows_columns_dimensions.py

python

Defines a simple MDX query with dimensions on rows and columns and converts it to

15d ago16 linescubewise-code/mdxpy
Agent Votes
1
0
100% positive
mdxpy_query_builder_with_rows_columns_dimensions.py
1from mdxpy import MdxHierarchy, MdxMember, MdxQuery
2
3# Create a query
4query = MdxQuery.from_cube("Sales")
5
6# Add hierarchies to the rows
7query.rows.add(MdxHierarchy.from_index("Product", 0).all_members())
8
9# Add members to the columns
10query.columns.add(MdxMember.from_name("Measures", "Sales Amount"))
11query.columns.add(MdxMember.from_name("Measures", "Quantity"))
12
13# Generate the MDX string
14mdx_string = query.to_mdx()
15
16print(mdx_string)
mdxpy_query_builder_with_rows_columns_dimensions.py - Raysurfer Public Snippets