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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MEDIAN 1

Status
Not open for further replies.

kimchavis

Technical User
Jan 7, 2004
66
US
Hello all.

I know this is probably simple, but I dont know how to do this one:

I need to get the Median for three fields in the details section.

for instance: Field 1 = 100
Field 2 = 150
Field 3 = 300

I want it to return 150.

Can someone help with this?
 
That doesnt work. The response is The summary/ Running total could not be created.

What Im looking to do is Median({field1}, {field2}, {field3})
 
the Median() function is designed to find the median of all the values in a single field or formula. You are trying to find the median of 3 separate fields. Therefore, you will most likely need to either: 1) write a formula that creates an array out of your 3 fields, then a second formula finding the median() value of that formula; or 2) manually write a formula to handle the median calculation. The second option is more complicated, and involves determining whether your result set is even or odd; then sorting the results by absolute value, then locating/calculating the median of those values.

I'd recommend searching for how to set up an array, then taking the medain of the array formula.
 
The following will find the median of 3 fields, replace the items in bold with your field names :

Local NumberVar Num1 := 100;
Local NumberVar Num2 := 300;
Local NumberVar Num3 := 150;

If Num1 < Num2 and Num1 > Num3 then Num1 else
If Num1 > Num2 and Num1 < Num3 then Num1 else
If Num2 < Num1 and Num2 > Num3 then Num2 else
If Num2 > Num1 and Num2 < Num3 then Num2 else
If Num3 < Num1 and Num3 > Num2 then Num3 else
If Num3 > Num1 and Num3 < Num2 then Num3

Reebo
UK

Please Note - Due to current economic forcast and budget constraints, the light at the end of the tunnel has been switched off. Thank you for your cooperation.
 
My apologies, Kim; I read this wrong.

This earlier thread (thread767-311646) handles this for this scenario, or any number of field values

Regards,

Naith

PS: Nice signoff, Reebo. [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top