First thing to consider when using IIF is what type of result we will get from the THEN and ELSE. I'm sure you've looked at the MDX Primer for this (as I did a while ago when having a similar requirement) and found the example relating to the IIF being used to decide whether to filter by the top 5 or 10 records.
In that case it was a numeric example; in this case we want to output some text... so we need to enclose the results in quotes.
If you have used StrToMember before you will know that when you use logic to build up a statement e.g. the classic most of us have used:
Code: Select all
StrToMember ( "[}Clients].[" + UserName + "]" )
We need to help the system understand that everything we are putting together is supposed to be processed as a single statement; this is us helping to tell the system the order in which it needs to work things out.
The problem is you want to build a set instead of just a member; so you can't use StrToMember... and that is where StrToSet comes in to play. This one works the exact same way as StrToMember but with the purpose of returning a set instead; I don't think its really documented in a TM1 context anywhere but you can get the gist from general MDX documents anyway and then work out how to apply it in TM1.
Long story short I think the below code should get you the result that you are looking for:
Code: Select all
StrToSet (
"{Filter ( {[Subsidiary].members},"
+
IIF (
COUNT ( {Filter ( {[Subsidiary].members},
[Subsidiary Year Mapping].([Year].CurrentMember, [Subsidiary Year Mapping Measure].[Select]) = "YES"
)}
) > 0,
"[Subsidiary Year Mapping].([Year].CurrentMember, [Subsidiary Year Mapping Measure].[Select]) = """ + "YES""",
"[Subsidiary].[Code] = """ + "FakeElement"""
)
+
")}"
)