tm1Ui promise calls and while loops


Does anyone have any recommendations on how to handle While loops with tm1Ui promise calls? I am trying to work my way up our hierarchy until I find an attribute match.

For example, but not the right way…

$scope.pcParent = data;
$scope.pcLevel = "";
while($scope.pcLevel != "Sector")
		$tm1Ui.dimensionElements($, "ProfitCenter", "Level", "", "{[ProfitCenter].[" + $scope.pcParent + "]}", "", "", false, false)
		          $scope.pcLevel = pcData[0].Attributes.Level;
		          $scope.pcParent = pcData[0].Parents[0].Name;

Or maybe there is an easier way to do this I am missing…



Hi @chet_watkins,

Instead of a while loop, a more direct way should be available via MDX. You can use FILTER for example and it can look like this:

{FILTER( {TM1SUBSETALL( [ProfitCenter] )}, [ProfitCenter].[Level] <> 'Sector')}

So check and try it out first on your subset editor to verify that the above gives what you are looking for already. If there are more, then you can just adjust the mdx filter accordingly.



I have been going down the MDX path after I posted that and our hierarchy is giving me issues since we have multiple parents.

The ideal way of using MDX for me would be to do something like Ascendants([ProfitCenter].[CustomerName]) then I can just loop through the results and pull out the elements that have the Level attribute values I want. My problem is that the function is bringing back the wrong parents. So I am trying to figure out the way to get the right ones.


Hi @chet_watkins,

How do you visually determine then which one is the correct parent if they all have the same Level attribute value? Or is there a specific attribute value that distinguishes them?

Another potential way without going through loops with the promise calls, is to execute the MDX with Ascendants, and then just to loop through the results instead. Are there lots of elements?

But still, looping through all of the parents, it still needs a specific rule or condition to find out which parent are you looking for.

Could you elaborate more on the parent element you are trying to search for?



Basically we have a level attribute that tells us when an element is a sector or division of a customer.

So for example,

All Customers
---- Division A Name
-------- Sector A Name
------------ Some parent Element
----------------- Customer Name

each of these elements has a “Level” attribute that tells me if they are a sector, division, customer, etc.

In my scenario, I have the customer name already, I am trying figure out that customers Sector and Division elements.

My issue is that customer name is also in a different consolidation

for example,
---- custom name
------- Customer name

The ascendants MDX call is bringing back the customs its in and not the one I really want…

Even the tm1Ui function with the request to return parents, only returns one of the two, and its the wrong one. =(


Hi @chet_watkins,

If the consolidation to be excluded is known, then how about excluding them from the result via EXCEPT?



I believe that would just remove one of the parents in the hierarchy I don’t want returned.


Hi @chet_watkins,

You can exclude more than one by nesting EXCEPT. Are the consolidations to be excluded known? Because if they are, you should be able to theoretically combine this with the other TM1* mdx functions to get and to filter the elements.



Just an FYI that I figured out a fix based on our dimensions. Thanks for the help.