Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Median number in crystal formulas 2

Status
Not open for further replies.

jchewsmith

Technical User
Nov 20, 2006
161
US
I have 3 numeric fields and I need to find the median of the 3 fields. What is the formula to do this?

 
The median is just an average, thus since you have three fields, you can create formula similar to this ({field1}+{field2}+field3})/3
 
kray,
The 'mean' would be the average of the three values. The 'median' is the middle value'.
-Andy
 
Yes I am looking for the middle number of the 3 fields.
 
Create a formula like this:

numbervar array x := [{table.field1},{table.field2},{table.field3}];
numbervar med:=0;
if
(
(
x[1]>=x[2] and
x[1]<=x[3]
) or
(
x[1]<=x[2] and
x[1]>=x[3]
)
) then
med := x[1] else
if
(
(
x[2]>=x[1] and
x[2]<=x[3]
) or
(
x[2]<=x[1] and
x[2]>=x[3]
)
) then
med := x[2] else
if
(
(
x[3]>=x[1] and
x[3]<=x[2]
) or
(
x[3]<=x[1] and
x[3]>=x[2]
)
) then
med := x[3];
med

-LB
 
Go figure after being out of college for over thirty years I would forgot the difference between Median and Mean :)

Good solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top