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

Is there a function similar to ViewCreateByMDX? #201

Closed user1493 closed 4 years ago

user1493 commented 4 years ago

Looking for a function that would create a cube view based on the MDX expression. This is like the ViewCreateByMDX functionality we have in PA.

MariusWirtz commented 4 years ago

Hi @user1493 ,

here is a sample:

import configparser

from TM1py import TM1Service, MDXView

config = configparser.ConfigParser()
config.read(r'config.ini')

mdx = """
SELECT
{[}Clients].Members} ON ROWS,
{[}Groups].Members} ON COLUMNS
FROM [}ClientGroups]
"""

mdx_view = MDXView(cube_name="}ClientGroups", view_name="my_new_view", MDX=mdx)

with TM1Service(**config['tm1srv01']) as tm1:
    tm1.cubes.views.create(view=mdx_view, private=False)

Note that you can't see MDX views in architect and perspectives

user1493 commented 4 years ago

Hi Marius,

Yes that makes sense, thank you very much for the sample!