RE: Saved search invalid expression error
I am trying to sum and substract the balances using saved search formula. but its giving ERROR: Invalid Expression. Please help!
I am using formula in saved search like this but its giving invalid expression error CASE WHEN {custrecord1} = ‘Expenses’ THEN {balance}+ CASE WHEN {custrecord1} = ‘Interest Expense’ THEN {balance}+ CASE WHEN {custrecord1} = ‘Adjustments’ THEN {balance}+ CASE WHEN {custrecord1} = ‘Depreciation’ THEN {balance}+ CASE WHEN {custrecord1} = ‘Revenue’ THEN {balance}+ CASE WHEN {custrecord1} = ‘Other Income’ THEN {balance}+ (CASE WHEN {custrecord1} = ‘Interest Earned’ THEN {balance}- CASE WHEN {custrecord1} = ‘Fixed Asset’ THEN {balance}) ELSE 0 END
The formula has error because you used multiple ‘CASE’ and yet used only one ‘END’.
If I read the operands, you try to do the ff:
- Expenses + Interest Expense + Adjustments + Depreciation + Revenue + Other Income + (Interest Earned – Fixed Asset)
Which is also similar to:
- Expenses + Interest Expense + Adjustments + Depreciation + Revenue + Other Income + Interest Earned – Fixed Asset
I also see that you are using 1 field ‘custrecord1’.
You can do the following in results:
- Formula (Numeric)
- Sum
- Formula:
CASE WHEN {custrecord1} IN (‘Expenses’, ‘Interest Expense’, ‘Adjustments’, ‘Depreciation’, ‘Revenue’, ‘Other Income’, ‘Interest Earned’) THEN NVL({balance},0) WHEN {custrecord1} IN (‘Fixed Asset’) THEN NVL({balance},0)*-1 ELSE 0 END
While the formula might work, I suggest do not ‘hardcode’ your formula to these names. You can make the list source of {custrecord1} as custom record, say “Account Type”, then create field (for example, dropdown field named ‘Balance Type’ with this selection ‘Positive Balance’, ‘Negate Balance’, ‘Zero’). Then you can shorten your formula to:
- CASE WHEN {custrecord1.balancetype} = ‘Positive Balance’ THEN NVL({balance},0) WHEN {custrecord1.balancetype} = ‘Negate Balance’ THEN NVL({balance},0)*-1 ELSE 0 END
So if I add ‘Account Type Line’, let’s say ‘Other Expense’, I just need to set it up as ‘Positive Balance’, then automatically it is included in the result since formula is not hardcoded to account type names.