*Formula Help Needed - Summary saved search* I ha...
# general
m
Formula Help Needed - Summary saved search I have 3 custom fields and am trying to get the minimum value out of the 3 and ignore if there is no value.. i.e. field A has 10, field B has 20, field C is empty/blank/0.. the output I would want is 10. I've got formula which gives me the minimum of the 3 fields however doesn't work to give me 10, rather gives me 0: Formula Numeric: Minimum:
LEAST(NVL({custitem_A}, 0), NVL({custitem_B}, 0), NVL({custitem_C}, 0))
Tried something like this as well however doesn't work:
CASE WHEN NVL({custitem_A}, '') = '' THEN CASE WHEN NVL({custitem_B}, '') = '' THEN NVL({custitem_C}, 0) ELSE LEAST(NVL({custitem_B}, 0), NVL({custitem_C}, 0)) END ELSE CASE WHEN NVL({custitem_B}, '') = '' THEN LEAST(NVL({custitem_A}, 0), NVL({custitem_C}, 0)) ELSE LEAST(NVL({custitem_A}, 0), NVL({custitem_B}, 0), NVL({custitem_C}, 0)) END END
Any ideas?
r
You could do something like NVL ({fieldid,999999999}) Should give you the correct. You are making null as 0 instead make null as so huge that it never is the least. You will have to handle the scenario in case all 3 are null with 0.
d
`for two fields, you can get away with
COALESCE(LEAST({A}, {B}), {A}, {B})
But for 3 fields it gets a bit messy:
Copy code
LEAST(COALESCE({A},{B},{C})
     ,COALESCE({B},{A},{C})
     ,COALESCE({C},{A},{B}))
I think raghav's approach is what I'd use, it's easily extendable. I'd probably use
binary_double_infinity
in case your field contains large numbers. Something like:
Copy code
NULLIF(
	LEAST(
		NVL({A}, binary_double_infinity),
		NVL({B}, binary_double_infinity),
		NVL({C}, binary_double_infinity)
	),
	binary_double_infinity
)