7 Replies Latest reply on Mar 12, 2010 11:33 AM by fitch

# Let function

### Title

Let function

### Post

I'm trying to use the let function and the case function in a calculation:

Let (  [TotalInvoice = "T" ; interest = "I";  Get (currentDate) - invoice date = "date" ]; Case ( date  ≥ 30; T + I); T)

I keep getting an error message saying I need a text constant,  number, field or parentheses  on the first parentheses of currentDate.   I don't know what else to do.

Thanks,

Carolyn Haywood

Beginner

• ###### 1. Re: Let function

Try:

Let([ T = TotalInvoice ; I = Interest ; D = Get ( CurrentDate ) - invoice date ]; Case ( D  ≥ 30 ; T + I ; T ))

• ###### 2. Re: Let function

Try this:

Let (

[

TotalInvoice = "T" ;

interest = "I";

date = Get (currentDate) - invoice date

];

Case ( date  ≥ 30 ; T + I  ; T )

)

• ###### 3. Re: Let function

Howdy Carolyn,

I'll take a stab at it, though another may correct me.

carolynhaywood wrote:

Let (  [TotalInvoice = "T" ; interest = "I";  Get (currentDate) - invoice date = "date" ]; Case ( date  ≥ 30; T + I); T)

The onboard help shows putting the variable to be set first, not second:

so Let (  [TotalInvoice = "T"...  should be Let ( T = TotalInvoice ; ....

The way you have it, you are setting TotalInvoice equal to "T" rather than the way you want it.

And the parenthesis causing the issue is probably the extra one you have in your Case statement.

Case (date >= 30 ; T+I ; T )  you have an extra ")" in yours that belongs at the end of the expression instead.

Edit: wow, two others beat me to it...must be typing slow this morning.

• ###### 4. Re: Let function

Thanks everyone for your quick responses!  I had two problems - one was reversing the let variables and the other was the parentheses in the case expression.

Thanks again,

Carolyn Haywood

• ###### 5. Re: Let function

The format for assigning variables using a let function is VariableName = Expression.  You are assigning the character "T" to a variable named TotalInvoice, The character "I" to a variable named intrest, and you are trying to assign the string "date" to something that is not a variable.  Also, your close parenthesis in the case statement should be after T.  Format should be case(test;result; test2;result2; default).

I am going to make a guess that TotalInvoice is a field in your database, along with intrest and invoice date.  If that is the case, your let statement should look like:

Let([

T = TotalInvoice;

I = intrest;

date = Get(CurrentDate) - invoice date];

Case (date ≥ 30; T + I; T)

)

Chris

I had to take a phone call.  Slowed me down on the answer

• ###### 6. Re: Let function

Thanks, Chris!

You solved my third problem - how to have more than one  "case".

• ###### 7. Re: Let function

A useful practice is to make the result a variable as well. This makes it easier to troubleshoot. E.g.:

```Let([
a = foo ;
b = bar ;
result = Case( something; a ; b )
] ;

result
)```

If I get an error or unexpected result, I can throw the calc into the Data Viewer (assuming we have FileMaker Advanced) and change the last "result" variable to "a" or "b" etc. to figure out what's going on.