Forum Discussion
c_laurenti
3 years agoFrequent Visitor
Find flight itinerary from flight legs
A flight with destination from A to B is composed by one or more legs. It has 2 legs if it has to stop to a intermediate destination C, going A -> C -> B. Suppose I have a table of flight legs, with ...
- 3 years ago
custom sorting
let Source = your_table, comparer = (x, y) => if x[Date] > y[Date] then 1 else if x[Date] < y[Date] then -1 else if x[Origin] = y[Destination] then 1 else if x[Destination] = y[Origin] then - 1 else 0, g = Table.Group(Source, "Id", {{"legs", each Table.Sort(_, comparer)}}), iti = Table.AddColumn(g, "itinerary", each Text.Combine([legs][Origin] & {List.Last([legs][Destination])}, "/")), legs = Table.TransformColumns(iti, {"legs", Table.RowCount}) in legs
c_laurenti
3 years agoFrequent Visitor
I did try it, and it did work. I didn't accept it as a solution because it doesn't handle the number of legs (although that is simple).
ronrsnfld
Super User
3 years ago- For my personal benefit, could you kindly supply a sample of data on which this fails. Thanks. Ron