1

In an analysis where each row contains e.g. a flight number, I'd like to filter down my active dataset to keep only the three most-delayed flight numbers for each carrier.

How do I accomplish this in Contour?

Adil B
  • 14,635
  • 11
  • 60
  • 78

1 Answers1

2

This is a two-step process: (1) Group and order, and (2) filter.

Group and Order: Add an Expression board, and make a new column by assigning a row number for each record. Reset the row number within each carrier group, and ensure that row numbers are assigned in order of flight delay duration.

row_number() OVER ( PARTITION BY "carrier" ORDER BY "delay_duration" DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) 

Filter: Add a Filter board and select those row numbers created above that are less than or equal to 3 to keep only the three most delayed flights for each carrier.

Andrew St P
  • 524
  • 1
  • 5
  • 13