Sep 3, 2020

Updating dimensions with TM1py

This article explains two different ways to update dimensions with TM1py.

Getting the full dimension information, manipulate it and send it back

The first way to update a dimension is to get all the dimension information then update the information and finally send the information back to TM1.

1. Retrieve the dimension from TM1 into python

with TM1Service(address=ADDRESS, port=PORT, user=USER, password=PWD, ssl=SSL) as tm1:        hierarchy = tm1.hierarchies.get(dimension_name="d1", hierarchy_name="d1")

2. Manipulate it

    hierarchy.add_element(element_name="e6", element_type="Numeric")    hierarchy.add_element_attribute(name="Attribute B", attribute_type="String")

3. Send it back to TM1

tm1.hierarchies.update(hierarchy=hierarchy)

Creating elements and attributes directly to the dimension

Occasionally it makes sense to use a shortcut. For instance, if you need to add just one element/attribute to a large dimension it doesn’t make sense to pull the full dimension over and send it back.

This is why new functions were added to the ElementService to interact with TM1 dimensions/hierarchies on an element level, such as:

  • create: insert a new element

  • create_element_attribute: create a new attribute

with TM1Service(address=ADDRESS, port=PORT, user=USER, password=PWD, ssl=SSL) as tm1:        # Add element e5 as Numeric to the dimension d1    tm1.elements.create(        dimension_name="d1",         hierarchy_name="d1",         element=Element("e5", "Numeric"))    # Create Attribute A as type String to the dimension d1    tm1.elements.create_element_attribute(        dimension_name="d1",        hierarchy_name="d1",        element_attribute=ElementAttribute("Attribute A", "String"))

Related content

Loading related content