cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
190 stars 109 forks source link

How to Create subset using mdx string #206

Closed reddibhatini closed 4 years ago

reddibhatini commented 4 years ago

Hello,

Is there a way to create a subset using MDX? Could not able to find a method for this.

Thank you

rclapp commented 4 years ago

I have a Method waiting on a pull request that lets you execute an MDX query against a dimension. A complimentary function that saves it as a subset would be nice.

Thanks,

Ryan Clapp

From: reddibhatini notifications@github.com Sent: Monday, January 27, 2020 8:45 AM To: cubewise-code/tm1py tm1py@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [cubewise-code/tm1py] How to Create subset using mdx string (#206)

Hello,

Is there a way to create a subset using MDX? Could not able to find a method for this.

Thank you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/cubewise-code/tm1py/issues/206?email_source=notifications&email_token=AEK7GZQ4IQ43FIR5N6MDB3LQ74FPBA5CNFSM4KMEOPN2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4II7I3EQ, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEK7GZXUVCHUEZS3CUNWMR3Q74FPBANCNFSM4KMEOPNQ.

MariusWirtz commented 4 years ago

Hi @reddibhatini, here is a sample:

with TM1Service(address=ADDRESS, port=PORT, user=USER, password=PASSWORD, ssl=SSL) as tm1:

    dimension_name = "}Clients"
    expr = "{TM1SubsetAll([}Clients])}"

    subset = Subset(
        subset_name="All Clients",
        dimension_name="}Clients",
        hierarchy_name="}Clients",
        expression=expr)
    if not tm1.dimensions.hierarchies.subsets.exists(
            subset_name=subset.name,
            dimension_name=dimension_name,
            hierarchy_name=dimension_name,
            private=False):
        tm1.dimensions.hierarchies.subsets.create(subset, private=False)
    else:
        tm1.dimensions.hierarchies.subsets.update(subset, private=False)

@rclapp Thanks for the MR. Much appreciated! Will look into it in more depth on the weekend. I agree. It would be nice to have a simplified method to create a subset from mdx with just one call.

reddibhatini commented 4 years ago

@rclapp @MariusWirtz Thank you. That was helpful. Yeah. I was looking for method call to create subset by mdx.