I’m working with an Airtable database that has a record containing 17 different numeric columns. What I need to do is identify the 5 highest values from all these columns combined and display them in a structured format.
Currently I can only get the maximum value using the MAX function, but I need something similar to Excel’s LARGE function to get the top 5 values ranked in order.
In PostgreSQL I was able to solve this using a query with lateral joins and window functions:
select data.*, results.*
from data cross join lateral
(select max(val.number) filter (where rank_num = 1) as top_value_1,
max(val.number) filter (where rank_num = 2) as top_value_2,
max(val.number) filter (where rank_num = 3) as top_value_3,
max(val.number) filter (where rank_num = 4) as top_value_4,
max(val.number) filter (where rank_num = 5) as top_value_5
from (select val.number, row_number() over (order by number desc) as rank_num
from (values (field_1), (field_2), (field_3)
) val(number)
) val
) results;
But I can’t figure out how to achieve the same result in Airtable. Is there a way to rank and extract multiple top values across several columns?