8 Replies Latest reply: May 15, 2014 10:05 AM by Ron_b _

# Calculated Field Using IF Statement

i am trying to run a calculated field that works out *2 if another field shows "Peak"

Any ideas how i can achieve this?

• ###### Calculated Field Using IF Statement

Hi,

Try if(="Peak",[Fare Field]*2,0).

• ###### Calculated Field Using IF Statement

Great that works however if i also want to return the value of if <>"Peak"???

Help is much appreciated.

• ###### Calculated Field Using IF Statement

Sorry, I assumed that you wanted 0.  Just change the 0 to .

• ###### Calculated Field Using IF Statement

I'm also trying to set the value of a user-defined field using an IF statement.  My report source looks like this small sample below where every line becomes a separate row with a field named ApptLine.

10:00 +OT name,name      3706491 555 555-2536

:10   | #13 MOD COMP

:20   | GSC

:30   |

:40   |

I'd like to set a user-defined field value to 1 IF the trapped line contains the '|' character.  I've tried various formulas such as If('|' .In.(ApptLine),1,0) to no avail.  Help, please.

• ###### Calculated Field Using IF Statement

Hi there

The .In. function works as FieldName.In.("Criteria") where criteria is the thing you are looking for enclosed in quotes, use a comma seperator for multiple criteria.

Regards

Nigel

• ###### Calculated Field Using IF Statement

Thanks.  So is there a formula operator for 'contains'?  Where I could say: if( 'contains' '|',1,0).  I'd like to assign the value 1 when the field has a | character.  If there's an alternative way I'd appreciate any suggestions.

• ###### Calculated Field Using IF Statement

Strictly speaking, this formula isn't for a "user-edited" field, as those particular types cannot accept formulas, but rather is for a "formula-based" field. I know this is case of "what I meant, not what I said", but for those reading this later on, let's clarify a little. No big deal.

As to the "contains" operator, what you want to use is the InStr() function, which returns the integer position of a specified string within a target string. If the search string doesn't exist within the target string, the function returns a zero value.

So what you're after is:

If(InStr("|",ApptLine)>0,1,0)[/code]

HTH,

Kruncher

• ###### Calculated Field Using IF Statement

Perfect, worked like a charm!  Thank you very much!