Nested @If Statements

I am new to Designer and have read the Help file and as much of the forum as I can Understand.

I am trying to calculate a field using @if statements.

Here is my formula:

@If(@Name([CN]; @UserName)=“first person’s name” : “second person’s name” : “third person’s name”);

@if(Difference<=94;(Difference - UnpaidMiles);94);

@if(Difference<=80;(Difference - UnpaidMiles);80);

It works until I add the last @if to it

this form is for a mileage report.

If the person is listed then check to see if the difference field is <= 94, if it is then subtract the Fields (Difference - UnpaidMiles)if not then I want them to have a maximum value of 94, If the person is not listed then check to see if the difference field is <= 80, if it is then subtract the Fields (Difference - UnpaidMiles)if not then I want them to have a maximum value of 80

Any help will be greatly appreciated

Thank you

Subject: You have a closing Paren after the first If Condition.

Try:IsListed := @Name([CN]; @UserName)=“first person’s name” : “second person’s name” : “third person’s name”;

DifUp := Difference - UnpaidMiles;

@If(IsListed; @If(Difference <= 94; DifUp; 94); Difference <= 80; DifUp; 80);

Subject: Nested @If Statements

It looks like you only have one misplaced parenthesis; you have an extra one after your list of three names, and you’re missing one at the end of the entire formula.

@If(@Name([CN]; @UserName) = “first person’s name” : “second person’s name” : “third person’s name”;

@if(Difference <= 94; (Difference - UnpaidMiles); 94);

@if(Difference <= 80; (Difference - UnpaidMiles); 80));

Also, you could use the @min function, and more correctly, you “should” be using the @ismember function:

@If(@ismember(@Name([CN]; @UserName); “first person’s name” : “second person’s name” : “third person’s name”);

@min(Difference - UnpaidMiles; 94);

@min(Difference - UnpaidMiles; 80));

or

max := @If(@ismember(@Name([CN]; @UserName); “first person’s name” : “second person’s name” : “third person’s name”); 94; 80);

@min(Difference - UnpaidMiles; max)

Subject: RE: Nested @If Statements

I tried all of the suggested formulas. They all pass the check by Designer but bring up an error when I try to Save.

The error is “Field: “MilesPaid”: Incorrect Datatype for operator or @function

Subject: RE: Nested @If Statements

Ok, so what is the datatype of the UnpaidMiles field? All the formulas attempted thus far have been assuming it’s of type Number. If it’s not, make it so.

Since you say your error is on save, not on compose, I expect you have a numeric default value for the field, but when you try to save the document, it gets converted to the type of the field – presumably text.

Incidentally, it’s a Really Bad Idea to hardcode specific usernames into the application. Use a role instead, or else keep a list somewhere – in a profile document would be good – that specially privileged users can edit, and compare the name to that list.

Also, you probably should not use @Username here. I don’t know what your intention is, but I suspect you want to calculate this figure based on the identity of the person who composed the document – not depending on the username of someone else who might later edit it. Get the original username stored in a Computed when Composed field, and use that field in your formula.

Subject: RE: Nested @If Statements

Thank you for the adviceThe UnpaidMiles field in a number field

Yes there is a numeric default in the field ‘the number 50’

Subject: RE: Nested @If Statements

What about the Difference field?

BTW you haven’t said the name of the field this formula is in. I’m assuming it’s MilesPaid, because that was mentioned in the error message – if not, you need to look at the formula of the MilesPaid field.

Subject: Nested @If Statements

Those aren’t nested – you’re missing th closing parenthesis that nests them. If I understand correctly, what you want actually looks like this:

@If(@Name([CN]; @UserName)=“first person’s name” : “second person’s name” : “third person’s name”; @if(Difference<=94;(Difference - UnpaidMiles);94); @if(Difference<=80;(Difference - UnpaidMiles);80))