4 Replies Latest reply on Sep 5, 2012 11:20 AM by philmodjunk

# Can you have more than one variable in a field calculation?

### Title

Can you have more than one variable in a field calculation?

### Post

Currently, I have a calculation that says:

Field B =

If ( FieldOne = FieldTwo; FieldA-1; FieldA)

So, if B = 4, and FieldOne and FieldTwo have the same number input, then FieldA shows a 3 - which is fine, that's what I'm after.

But, I need another variable stating that

If ( FieldOne > FieldTwo; FieldA-2; FieldA )

So, if B = 4, and Field One has a higher number input than Field Two, then FieldA would show a 2.

I can get the calculation to work with only the first formula but if I ask it to evaluate both "Ifs" I don't get the correct calculation. I thought all I had to was put in both calculations with " or " between them, but that doesn't work.

• ###### 1. Re: Can you have more than one variable in a field calculation?

You might consider nesting the functions inside one another or use the Case function.

What do you want to happen if FieldOne < FieldTwo, FieldA?  You might try:

Field B =

Case(FieldOne = FieldTwo; FieldA-1;    FieldOne < FieldTwo; FieldA;     FieldOne > FieldTwo; FieldA-2;    "")

I'm kind of a novice so test this out and read about "Case" from the link I provided.

• ###### 2. Re: Can you have more than one variable in a field calculation?

I'm afraid that what you have written doesn't make sense to me.

Field B =

If ( FieldOne = FieldTwo; FieldA-1; FieldA)

So, if B = 4, and FieldOne and FieldTwo have the same number input, then FieldA shows a 3 - which is fine, that's what I'm after.

If Field B is a calculation field with this expression, You can't set B to be 4. If you meant that A = 4 and Fieldone = FieldTwo, then what you have posted makes sense.

Making the same changes here:

If ( FieldOne > FieldTwo; FieldA-2; FieldA )

So, if A = 4, and Field One > Field Two, then Field B would show a 2.

Then the Case function already recommended should do the job
case ( Fieldone = Field2 ; FieldA - 1;
FieldOne > Field2 ; FieldA -2 ;
FieldA )

Note that with this expression B will show the value of A if FieldOne < Field2 That's the function of the last term shown in blue above.

• ###### 3. Re: Can you have more than one variable in a field calculation?

Hey Phil - This is one of those examples I was telling you about. If you saw the file for yourself, I could explain my issue much better.

Charlie

• ###### 4. Re: Can you have more than one variable in a field calculation?

What you posted was impossible to set up in fileMaker without changes.