Forum Discussion
JohnErdmann
5 months agoQrew Trainee
rvalenzTo ensure order I recommend breaking the solution into 2 formula queries.
1) A rank order query can be constructed with something like this in the target table:
Size(GetRecords("{3.LTE." & [Record ID#] & "}))
This example ranks each record, where the lowest record ID gets a return value of 1, but you could use a similar approach on any fields.
2) A formula to find the median based on rank order (doesn't need to live in target table, but can):
// Number of records where the target field is not missing
var number n = Size(GetRecords("{3.XEX.}"));
// Middle index when n is an odd number
var number i = Round($n / 2);
// Lower and upper bounds for middle ranks of the target variable
var number lb = SumValues(GetRecords("{6.EX." & $i & "}"), 3);
var number ub = SumValues(GetRecords("{6.EX." & ($i + 1) & "}"), 3);
If(Mod($n, 2) = 1,
$lb, // n is odd
($lb + $ub) / 2) // n is even, so sum 2 middlest records and divide by 2