Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Integrate TM1 data into Alteryx workflows

yuxuanxie
5 - Atom

Anyone have experience integrating IBM Planning Analytics data into Alteryx workflows? I found some info on the internet about using Macros but don't really know how to utilize.

5 REPLIES 5
stumptownscott
5 - Atom

I would also be curious if anyone has had success with this. Currently, I'm pulling data from IBM Planning Analytics (TM1) via the Excel Add-In, then saving the file, then opening Alteryx grab the result from the file and finish up the work. But the Excel Add-In is slow, and it's an extra step I don't want my users to have to do.

aatalai
14 - Magnetar

I would also be interested in news in this area

AnnaMurphy88
5 - Atom

Has anyone figured this out? This would save me so much time!

Douard
5 - Atom

Yes, we use this. We have TM1 on Cloud (TM1OC) so you will need to get hold of the non-interactive account details from your TM1 admin. If you use TM1 on premise you will be able to pass in your username and password. Search Cubewise TM1PY on the web for the connection strings.

 

In Alteryx you connect using the Python tool. The following code will get data from cube using the MDX you pass.

 

# List all non-standard packages to be imported by your
# script here (only missing packages will be installed)
from ayx import Package
Package.installPackages(['pandas','numpy','tm1py'])

 

from ayx import Alteryx
import pandas as pd #importing librbary required for tm1py
from TM1py.Utils.Utils import build_pandas_dataframe_from_cellset #importing library required to interact with PA
from TM1py.Utils import Utils
from TM1py.Services import TM1Service


#tm1 configs
src_base_url = "https://your_instance.planning-analytics.cloud.ibm.com/tm1/api/TM1_server_name"
src_verify = True
src_namespace = "LDAP"
src_user = "your_non-interactive_account_username_tm1_automation"
src_pw = "password"

with TM1Service(

base_url=src_base_url,
user=src_user,
namespace=src_namespace,
password=src_pw,
ssl=True,
verify=True,
async_requests_mode=True) as tm1:
mdx = """
SELECT...

NOTE: you can get the MDX from your PAfE add in - open it in the viewer and copy the MDX code here
    """
# retrieve a dictionary through TM1py and build a DataFrame from it,
data = tm1.cubes.cells.execute_mdx(mdx)
df = build_pandas_dataframe_from_cellset(data, multiindex=False)
Alteryx.write(df,1)

 

sebsimpson
5 - Atom

Thanks Douard! Have used this already as a PA on Cloud customer thanks to your assistance (TM1 11 - note that the syntax is different for 12). Would like to elaborate on a few things for clarity due to some issues I faced in case others face similar, as well as providing some further info I found whilst investigating.

 

Please note that a lot of the docs have the domain section of the URL wrong for the environments, at least compared to ours (.ibmcloud.com vs cloud.ibm.com). This tripped me up initially!

 

I would recommend a slightly different initial query to get people started. You can generate an MDX view as mentioned but initially validating the connection is probably the best thing to do. I personally used a separate python tool in Alteryx to do the initial packages install. Worth noting here that you will need to run Alteryx as administrator to give it windows file write permissions to install tm1py:

 

from ayx import Package
Package.installPackages(['pandas','numpy','tm1py','requests','requests-negotiate-sspi'])

 

The requests and requests-negotiate-sspi are unlikely necessary but I included them just in case, as dependencies for tm1py.

 

In all examples below, replace the bits in square brackets (including the brackets) with the necessary entry. E.g. if your environment name is MyCompanyDev, and your instance/server is InstanceOne, your base_url will look like:

base_url='https://MyCompanyDev.planning-analytics.ibmcloud.com/tm1/api/InstanceOne/'

 

Next comes a simple connection check (I ripped this from Errol Brandt's post).

 

### import the TM1py libraries
from TM1py.Services import TM1Service
from TM1py.Exceptions import TM1pyException

try:
    with TM1Service(
            base_url='https://[YourEnvironmentName].planning-analytics.ibmcloud.com/tm1/api/[YourServerName]/',
            user="[YourAutomationUser]",
            namespace="LDAP",
            password="[YourAutomationUserPassword]",
            ssl=True,
            verify=True,
            async_requests_mode=True) as tm1:

     print ('Connected!')

except TM1pyException as e:

if e.status_code == 401:
    print('The user credentials were rejected. Check username and password.') 

elif e.status_code == 404:
    print('The connection was rejected. Check the connection string.')

else:
    print('Something else went wrong. Check error code ' + str(e)). 

 

Once you are all connected, a "self-serve" method would be to pull a view from TM1 (allows users with both Alteryx and TM1 to create their own public/private views, and less difficult to modify than MDX). Just flip the private Boolean to True if a private view. Marius has created optimised statements that avoid the need to call a view/mdx view and separately convert to a dataframe with pandas, which makes it a bit simpler too:

 

from TM1py.Services import TM1Service
from ayx import Alteryx

with TM1Service(
		base_url='https://[YourEnvironmentName].planning-analytics.ibmcloud.com/tm1/api/[YourServerName]/',
		user="[YourAutomationUser]",
		namespace="LDAP",
		password="[YourAutomationUserPassword]",
		ssl=True,
		verify=True,
		async_requests_mode=True) as tm1:
    df = tm1.cubes.cells.execute_view_dataframe(
        cube_name="[YourCubeName]",
        view_name="[YourViewName]",
        private=False,
        parse_dates=[0],
        dtype={'Value': float})
    
Alteryx.write(df,1)

 

You can read about all of the classes and methods here.

Labels