MDX IIF to check if Element Exists
Posted: Thu Sep 04, 2025 4:31 pm
Hi,
I am trying to write some MDX which will return a subset depending on who is logged in.
For Admin users it should just return all elements.
For Super Users it would also return all elements.
For Planning users it should only return the elements they created, i.e. added to the dimension.
The problem is if a Planner logs in and they have not created any added elements then the view throws an error and the subset is empty saying "Internal Error 500".
The MDX is as follows:
Basically when a user adds a new employee into the system it creates a consolidated element called "UserAdded_clientname" and the elements get added to this parent.
The count part of the MDX was an attempt to avoid the error but it errors because it cannot find the element to do the count.
I also tried the following but this basically does the same as count,
Can anyone think of a way to avoid the error by checking if the logged on user has added any elements? If not I will have to create an attribute against the client.
Maren
I am trying to write some MDX which will return a subset depending on who is logged in.
For Admin users it should just return all elements.
For Super Users it would also return all elements.
For Planning users it should only return the elements they created, i.e. added to the dimension.
The problem is if a Planner logs in and they have not created any added elements then the view throws an error and the subset is empty saying "Internal Error 500".
The MDX is as follows:
Code: Select all
STRTOSET(IIF([}ClientGroups].([}Groups].[Planning],STRTOMEMBER("[}Clients].[" + USERNAME + "]")) <> 'Planning',"TM1SubsetToSet([Employee].[Employee] , 'Added Employees' , 'public')", IIF( COUNT(TM1FILTERBYLEVEL(Descendants(STRTOMEMBER('[Employee].[UserAdded_' + STRTOMEMBER("[}Clients].[" + USERNAME + "]").PROPERTIES("ClientName") + ']')),0)) = 0, "{[Employee].[Please Select]}","{TM1FILTERBYLEVEL(Descendants(STRTOMEMBER('[Employee].[UA_' + STRTOMEMBER('[}Clients].[' + USERNAME + ']').PROPERTIES('ClientName') + ']')),0)}")))
The count part of the MDX was an attempt to avoid the error but it errors because it cannot find the element to do the count.
I also tried the following but this basically does the same as count,
Code: Select all
VAL(STRTOMEMBER('[Employee].[UserAdded_' + STRTOMEMBER("[}Clients].[" + USERNAME + "]").PROPERTIES("ClientName") + ']').PROPERTIES("member_weight")) > 0
Maren