8 Replies Latest reply on Feb 9, 2017 5:08 PM by philmodjunk

# Which part of my mind have I lost?

So I'm setting up a CF. Here it is:

Chooser(fromList;toList;resultList;testValue):

Let([

fCount=ValueCount(fromList);

tCount=ValueCount(toList);

rCount=ValueCount(resultList);

fVal=GetValue(fromList;1);

tVal=GetValue(toList;1);

rVal=GetValue(resultList;1)];

Case(

rCount=0;0;

Sum(fCount;tCount;rCount)/3≠rCount;"Check the tier setup.";

(testValue>=fVal) and (testValue<tVal);rVal;

Chooser(RightValues(fromList;fCount-1);RightValues(toList;tCount-1);RightValues(resultList;rCount-1);testValue)

)

)

Always returns 0. If I echo out any of those "count" variables before the case statement, they come out right. But inside the case statement they all evaluate as 0. Since when was scoping a thing in FM???

Or am I missing something stupid?

• ###### 1. Re: Which part of my mind have I lost?

Is testValue a field? It's not defined in your Let Statement.

• ###### 2. Re: Which part of my mind have I lost?

Where did this come from? Is it a custom function? There is no native function like that. Though there is a Choose function.

• ###### 3. Re: Which part of my mind have I lost?

Check the smaller parts individually, as well, like you did with the "count" variables.

• Sum(fCount;tCount;rCount)/3
• (testValue>=fVal)
• (testValue<tVal)

Or make those a part of the Let variables to make it easier to check.

• ###### 4. Re: Which part of my mind have I lost?

To help me develop and analyse complex Let ( ) calcs like this I usually set the desired result up as a parameter, and then reference that at the bottom of the calc. This makes it easy then to examine the outcome of each parameter to spot what may be going wrong—

Let(

[

fCount = ValueCount ( fromList ) ;

tCount = ValueCount ( toList ) ;

rCount = ValueCount ( resultList ) ;

fVal = GetValue ( fromList ; 1 ) ;

tVal = GetValue (toList ; 1 ) ;

rVal = GetValue ( resultList ; 1 ) ;

result = Case(

rCount = 0 ; 0 ;

Sum ( fCount ; tCount ; rCount ) / 3 ≠ rCount ; "Check the tier setup." ;

( testValue >= fVal ) and ( testValue < tVal ) ; rVal ;

Chooser ( RightValues ( fromList ; fCount-1 ) ; RightValues ( toList ; tCount-1 ) ;

RightValues ( resultList ; rCount-1 ) ; testValue )

] ;

result     //NOTE: to examine another parameter, just substitute its name here

)

1 of 1 people found this helpful
• ###### 5. Re: Which part of my mind have I lost?

See the top - I'm setting up a custom function and testValue is the last parameter.

• ###### 6. Re: Which part of my mind have I lost?

Bruce - yes, a custom function - that's what I meant in the top line where it says I'm setting up a CF.

• ###### 7. Re: Which part of my mind have I lost?

Thanks for the replies, everyone! I guess I may never know which part of my mind was missing...I copied this function into another system and it worked perfectly. No idea why!!

• ###### 8. Re: Which part of my mind have I lost?

Hmmm, saw a bit of brain running through here earlier, yours?