Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated MDX is incorrect with multiple dimensions on row or column Axis. #55

Open
swaterbury-CW opened this issue Feb 11, 2025 · 3 comments

Comments

@swaterbury-CW
Copy link

swaterbury-CW commented Feb 11, 2025

When using:

  for dim in dims:
        elements_dict = tm1.elements.get_leaf_elements(dimension_name=dim, hierarchy_name=dim)
        print(dim)
        element_sample = elements_dict
        if elements_dict.__len__() > 10:
            k = int(round(len(elements_dict) * percent, 0))
            element_sample = random.sample(elements_dict, k=1)

        if dim == dims[0]:
            for el in element_sample:
                mdx = mdx.add_member_tuple_to_columns(el.unique_name)
        else:
            for el in element_sample:
                mdx = mdx.add_member_tuple_to_rows(el.unique_name)

MDX generated follows the format on row Axis of

{([Dim1].[Dim1].[Dim1Element]),([Dim2].[Dim2].[Dim2Element])}

This is an incorrect MDX string for multiple stacked dimensions and it fails to render. When manually modified to:

{[Dim1].[Dim1].[Dim1Element]}*{[Dim2].[Dim2].[Dim2Element]}

MDX Returns successfully and without error.

@rclapp
Copy link
Collaborator

rclapp commented Feb 11, 2025 via email

@MariusWirtz
Copy link
Collaborator

@swaterbury-CW
I think mdxpy is doing what it should do actually.

I think you are doing something illegal when you place a set of tuples with different dimensionality on one axis:

{
  ([Dim1].[Dim1].[Dim1Element]),
  ([Dim2].[Dim2].[Dim2Element])
} ON ROWS

It would be the same as this:

SELECT 
{
([Product].[Bike A]),
([Year].[2025]),
([Region].[Germany])
} ON ROWS
...

I think if you add MDX sets to the axes instead of MDX tuples you get what you need.

for dim in dims:
    elements_dict = tm1.elements.get_leaf_elements(dimension_name=dim, hierarchy_name=dim)
    print(dim)
    element_sample = elements_dict
    if elements_dict.__len__() > 10:
        k = int(round(len(elements_dict) * percent, 0))
        element_sample = random.sample(elements_dict, k=1)

    if dim == dims[0]:
        mdx_set = MdxHierarchySet.members([Member.of(el.unique_name) for el in element_sample])
        mdx = mdx.add_hierarchy_set_to_column_axis(mdx_set)
    else:
        mdx_set = MdxHierarchySet.members([Member.of(el.unique_name) for el in element_sample])
        mdx = mdx.add_hierarchy_set_to_row_axis(mdx_set)

This should produce an MDX like this:

SELECT 
{[Product].[Bike A], [Product].[Bike B], [Product].[Bike C]} *
{[Year].[2025]} *
{[Region].[Germany], [Region].[Austria], [Region].[Switzerland]}
 ON ROWS
...

@rclapp
Copy link
Collaborator

rclapp commented Feb 12, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants