I have the following data, values at End1, End2 appears in an order, I want to have another column that determines the order at which it appear at End1. There is a possibility that value at End2 may never reach at End1, but if it appears anywhere, it will have an impact on the order next item.
ID End1 End2
1 A B
1 A B
1 B A
1 A B
1 C B
1 C D
1 D C
1 C D
1 D C
2 A B
2 A B
2 A C
2 A C
2 C A
2 C A
2 D C
2 C D
2 D C
I want to have the following output:
ID End1 End2 Order
1 A B 1
1 A B 1
1 B A 2
1 A B 1
1 C B 3
1 C D 3
1 D C 4
1 C D 3
1 D C 4
2 A B 1
2 A B 1
2 A C 1
2 A C 1
2 C A 3
2 C A 3
2 D C 4
2 C D 3
2 D C 4
I tried different functions, but they are all counting the occurrences of the value. Any help is appreciated.
UPDATE: There are two other requirements here:
- The Order resets for each group. While A may have order 1 in ID=1, but it may have order 2 for any other ID.
- Some of the suggested solutions are not taking into account that a item at End2 (As for B in ID=2), may never reach at End1. But it will impact the order of items coming after it.
To make it more clear ID=3 within the same data set may have the following data:
ID End1 End2
2 D C
.....
3 B E
3 E B
3 E B
3 G B
3 C B
And the output required would be
ID End1 End2 Order
2 D C 4
.....
3 B E 1
3 E B 2
3 E B 2
3 G B 3
3 C B 4