Hi,
I have a requirement where we need to check if an ID is present in previous 12 month and if ID is not present in previous 12 month then assign them as a flag 1 else 0.
Please suggest.
Output will be like below:
Date | ID | Amount | Output |
201501 | 10 | 1.52660874 | 1 |
201502 | 10 | 51.25355684 | 0 |
201503 | 10 | 37.52812854 | 0 |
201504 | 10 | 96.81300912 | 0 |
201505 | 10 | 43.60392725 | 0 |
201506 | 10 | 73.22182503 | 0 |
201507 | 10 | 32.14007053 | 0 |
201508 | 10 | 74.13809993 | 0 |
201509 | 10 | 79.79684427 | 0 |
201510 | 10 | 77.31902323 | 0 |
201511 | 10 | 60.58766742 | 0 |
201512 | 10 | 89.81494418 | 0 |
201601 | 10 | 76.25828823 | 1 |
201602 | 10 | 98.94380309 | 0 |
201603 | 10 | 2.264243481 | 0 |
201604 | 10 | 49.97635792 | 0 |
201605 | 10 | 65.59688579 | 0 |
201606 | 10 | 81.88385109 | 0 |
201607 | 10 | 19.96448703 | 0 |
201608 | 10 | 32.05044517 | 0 |
201609 | 10 | 75.67336738 | 0 |
201610 | 10 | 47.15777796 | 0 |
201611 | 10 | 84.63246796 | 0 |
201612 | 10 | 89.80136739 | 0 |
201701 | 20 | 43.13358216 | 1 |
201702 | 20 | 47.98122389 | 0 |
201703 | 20 | 61.65518162 | 0 |
201704 | 20 | 87.91082823 | 0 |
201705 | 20 | 37.78389801 | 0 |
201706 | 20 | 38.28793545 | 0 |
201707 | 20 | 38.90115732 | 0 |
201708 | 20 | 50.7117456 | 0 |
201709 | 20 | 29.7799753 | 0 |
201710 | 20 | 6.346171884 | 0 |
201711 | 20 | 42.36902057 | 0 |
201712 | 20 | 48.66269228 | 0 |
201801 | 20 | 86.30545786 | 1 |
Thanks
Are you looking to do this in the script? Also, why is 201601 for ID 10 = 1?
We do have last 12 months for ID 10 prior to 201601, don't we?
Want to do using expression and ID 10 = 1 because this is appearing after 12 month.