Computed field - Default to Zero, but replace with computed value?

I have a Computed field called: ‘CurrentPrice_1’ with value of:

@If(ProductCode_1 = “”; “” ;@DbLookup(“”:“”;“”:“”;“LookupProductCodeDesc”; ProductCode_1; 3). This formula populates CurrentPrice_1 with a dollar value eg. 12000.

I have multiple product codes and prices.

The formual is working fine, but when I try to display the value in a view, I’m getting the error ‘Incorrect Data Type for operator or @Function, Number expected’. I know this error is referring to the blank CurrentPrice fields. What I need to do, is to have the other CurrentPrice fields (1-9) default to a zero, but be replaced with the correct value if a Product Code is selected.

Your help would be very much appreciated.

Regards,

Marion Ballingall

Subject: Two solutions

  1. Fix the column formula in the view to handle blank values.

  2. Set the value to 0 instead of blank in your code:

@If(ProductCode_1 = “”; “0” ;@DbLookup(“”:“”;“”:“”;“LookupProductCodeDesc”; ProductCode_1; 3)

Subject: A comment

Karl-Henry said to use:

@If(ProductCode_1 = “”; “0” ;@DbLookup(“”:“”;“”:“”;“LookupProductCodeDesc”; ProductCode_1; 3)

If the view column formula is expecting a number, you will do better with:

@If(ProductCode_1 = “”; 0 ;@DbLookup(“”:“”;“”:“”;“LookupProductCodeDesc”; ProductCode_1; 3)

Hope this helps,

Phil

Subject: Good catch

Got a bit late there. :slight_smile:

The original posted should probably also include a conversion of potential text values to numeric values in the column.

@TextToNumber(@Text(fieldname)) or something like that.

Subject: Thanks to both of you for your help it works.