I have a dataset (Airport Location Codes) e.g. London (LHR), Paris (CDG), Rome (FCO) etc on each row.
On some rows the entry might be London, London, London, Paris. which I planned to remove by clearing duplicates however on some instances I have genuine duplicates e.g. London, Paris London. Where I want to retain the final both London's because there was another location in between. If we consider Airport codes, the route might look like this -
LHR, LHR, CDG, FCO, FCO (Change to LHR-CDG-FCO) -
LHR, LHR, CDG, CDG, CDG, LHR (Change to LHR-CDG-LHR) What I was able to Achieve is Distinct List where it just returned LHR-CDG.
The number of times a code could appear is dynamic.
Is there function available in PowerQuery that could return this type of logic?
Sample data:
| ID | Route | Required Result |
|---|---|---|
| 1 | LHR, LHR, CDG,CDG, FCO | LHR-CDG-FCO |
| 2 | AMS, AMS, LHR, CDG | AMS-LHR-CDG |
| 3 | AMS, AMS, LHR, AMS, AMS | AMS-LHR-AMS |
| 4 | CGN-CGN-AMS-AMS-AMS-CDG-CDG-AMS | CGN-AMS-CDG-AMS |
| 5 | CGN-CGN-CDG-CDG-CDG | CGN-CDG |
