# calculated field expression

• 06-25-2011, 05:52 AM
Kamel
calculated field expression
hi all,

how I can put some thing like this in calculated field expression:

if(M_filter = "Oil", M_filter_oil_price, 0)
if(M_filter = "Air", M_filter_air_price, 0)
if(M_filter = "Fuel", M_filter_fuel_price, 0)

Please any help or suggestion !?
• 06-25-2011, 06:40 AM
Ray in Capetown
Re: calculated field expression
Quote:

Originally Posted by Kamel
hi all,

how I can put some thing like this in calculated field expression:

if(M_filter = "Oil", M_filter_oil_price, 0)
if(M_filter = "Air", M_filter_air_price, 0)
if(M_filter = "Fuel", M_filter_fuel_price, 0)

Please any help or suggestion !?

result = case(M_filter = "Oil", M_filter_oil_price,M_filter = "Air", M_filter_air_price,M_filter ="Fuel", M_filter_fuel_price..

Apologies if this has already been answered, I called away for a couple of hours
Ray
• 06-25-2011, 09:12 AM
Kamel
Re: calculated field expression
thanks Ray,

but it doesn't work with calculated field expression,
case() doesn't listed in functions list,,,
• 06-25-2011, 10:35 AM
Re: calculated field expression
Quote:

Originally Posted by Kamel
hi all,

how I can put some thing like this in calculated field expression:

if(M_filter = "Oil", M_filter_oil_price, 0)
if(M_filter = "Air", M_filter_air_price, 0)
if(M_filter = "Fuel", M_filter_fuel_price, 0)

Please any help or suggestion !?

I tried this assuming that M_filter_oil_price, M_filter_air_price, and M_filter_fuel_price are seperate fields for each record.
I created a calculated field named Cprice in the Query(DBF) section, with the following code
Code:

` case(M_Filter="Oil",M_Filter_Oil_Price,M_Filter="Air",M_Filter_Air_Price,M_Filter="Fuel",M_Filter_Fuel_Price)`
This accomplishes what you asked for, but does not seem to be what you really wanted.
• 06-25-2011, 10:40 AM
Peter.Greulich
Re: calculated field expression
Case is a valid function. But I guess it depends where you are defining it. If you are partial to IF, try this:

if(M_filter = "Oil", M_filter_oil_price, if(M_filter = "Air", M_filter_air_price, if(M_filter = "Fuel", M_filter_fuel_price, 0)))
• 06-25-2011, 01:12 PM
Re: calculated field expression
I tried using IF in the clientside calculations, but kept getting a circular reference error.
• 06-25-2011, 01:17 PM
Peter.Greulich
Re: calculated field expression
Quote:

I tried using IF in the clientside calculations, but kept getting a circular reference error.

Where are you using this?
• 06-25-2011, 01:31 PM
Re: calculated field expression
Hi Peter,

The attached pic says it so much better than I can.

I know I didin't get to the false part of the statement, but the error showed up before I got that far.
• 06-25-2011, 01:46 PM
Peter.Greulich
Re: calculated field expression
Yeah, client side expressions are basically JavaScript. Alpha gives us some basic "wrapper" functions, but they are very limited.
• 06-25-2011, 04:02 PM
Kamel
Re: calculated field expression
Quote:

Originally Posted by Peter.Greulich
Case is a valid function. But I guess it depends where you are defining it. If you are partial to IF, try this:

if(M_filter = "Oil", M_filter_oil_price, if(M_filter = "Air", M_filter_air_price, if(M_filter = "Fuel", M_filter_fuel_price, 0)))

Thanks Peter,
that what i want, :)
• 06-25-2011, 04:27 PM
Re: calculated field expression
Where are you planning to put that code (I'm a bit curious because of the trouble I had with it) ?
• 06-25-2011, 06:34 PM
Davidk
Re: calculated field expression
Quote:

Hi Peter,

The attached pic says it so much better than I can.

I know I didin't get to the false part of the statement, but the error showed up before I got that far.

What's "a result_false" in the else part of the statement? It looks like that is what's causing the problem - it would be interpreted as 2 variables or field names. Peter's "if" statement works in the client-side properties, calculated field expression - you're allowed the nested if statements in there - it gets converted to the equivalent javascript nested if statement.
• 06-25-2011, 07:10 PM
Re: calculated field expression
Quote:

Originally Posted by Davidk
What's "a result_false" in the else part of the statement? It looks like that is what's causing the problem - it would be interpreted as 2 variables or field names. Peter's "if" statement works in the client-side properties, calculated field expression - you're allowed the nested if statements in there - it gets converted to the equivalent javascript nested if statement.

I tried it exactly as described, and I still get the error (please see attached image).
• 06-25-2011, 10:39 PM
Davidk
Re: calculated field expression
Now we need to find out what M_filter, M_filter_oil_price, M_filter_air_price, and M_filter_fuel_price are, Are these calculations that reference themselves? A circular reference is a variable, field, etc. that references itself in the calculation thereby creating a reference that goes around and around in a circle and can never be evaluated.
• 06-25-2011, 11:31 PM
Re: calculated field expression
Quote:

Originally Posted by Davidk
Now we need to find out what M_filter, M_filter_oil_price, M_filter_air_price, and M_filter_fuel_price are, Are these calculations that reference themselves? A circular reference is a variable, field, etc. that references itself in the calculation thereby creating a reference that goes around and around in a circle and can never be evaluated.

They are fields.
• 06-26-2011, 09:34 AM
Davidk
Re: calculated field expression
In your last image showing the error you had an extra ending paren ")" but that would produce an evaluation error. Which field is this calculation attached to?
• 06-26-2011, 10:11 AM