'CTE SQL to flag 'yes' and 'No' - new entry id as 'yes' in current period compared over all previous months

MonthendDate Id period New id flag
31/12/2021 BBP026 Current No
31/12/2021 PRD002 Current Yes
31/12/2021 FCI008 Current No
31/12/2021 IPS004 Current No
31/12/2021 TRA005 Current No
31/12/2021 SEC002 Current Yes
30/11/2021 BBP026 Prior No
30/11/2021 FCI008 Prior No
30/11/2021 IPS004 Prior No
30/11/2021 TRA005 Prior No
31/10/2021 BBP026 Prior No
31/10/2021 FCI008 Prior No
31/10/2021 IPS004 Prior No
31/10/2021 PRD96 Prior No
30/09/2021 BBP026 Prior No
30/09/2021 FCI008 Prior No
30/09/2021 IPS004 Prior No
30/09/2021 PRD96 Prior No
30/09/2021 PRD09 Prior No

Hello all - I need help with CTE SQL to flag 'yes' and 'No'. ID column is unique to a month. id need to be compared to all the previous month. If Id is new then flag them as 'yes' in the current period and others as 'No'

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source