Tm1py: element_type value

Created on 14 Jul 2020  路  3Comments  路  Source: cubewise-code/tm1py

Describe what did you try to do with TM1py
What is the right way to compare the element_type property?

I tried the following to check if it is a consolidated element. But did not work.

  • if element.element_type == 'Consolidated':

Can it recognize the string above rather than the enum type?

  • if element.element_type == Element.Types.CONSOLIDATED:

Version

  • TM1py 1.5.0
question

All 3 comments

@fidong

It is a good practice to provide some code to replicate what you are trying to do. Anyway, since you are talking about element_type, the below part should help you solve that.

from TM1py.Services import TM1Service


with TM1Service(address=ADDRESS, port=PORT, ssl=SSL, user=USER, password=PASSWORD) as tm1:
    element_type_dict = tm1.elements.get_element_types(dimension_name='Period', hierarchy_name='Period')

    # filter the dict with the required element name to find its element_type
    if element_type_dict['01'] == 'Consolidated':
        print("A Consolidated element")

    # filter the dict with the required element name to find its element_type
    if element_type_dict['01'] == 'Numeric':
        print("A Numeric element")

    # loop through the dict and print all element names & types
    for element, _type in element_type_dict.items():
        print(f'"{element}" is a {_type} element')

@fidong,

in case you are dealing with the Element object, you can just explicitly convert the enum type into a str before you do the comparison.

from TM1py.Services import TM1Service

with TM1Service(address="localhost", port=12354, ssl=True, user="admin", password="apple") as tm1:
    hierarchy = tm1.hierarchies.get(dimension_name="Product", hierarchy_name="Product")

    element = hierarchy.get_element("483")

    if str(element.element_type) == "Numeric":
        print(element.name)

Thanks all yes that explains what I should do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scrumthing picture scrumthing  路  4Comments

Andy-Hofelmeyer picture Andy-Hofelmeyer  路  3Comments

ykud picture ykud  路  6Comments

cubewise-gng picture cubewise-gng  路  3Comments

ianboltz picture ianboltz  路  5Comments