'SQL for Monthly YOY (percentage change while keeping the monthly data frequency)?

Suppose I have a table called monthly metrics. Sample row in table below:

EOM BRAND METRIC
1/31/2021 Nike 100
2/28/2021 Adidas 68
1/31/2022 Nike 110
2/28/2022 Adidas 68
... ... ...

How do I get:

EOM BRAND METRIC YOY_CHANGE
1/31/2021 Nike 100 Null
1/31/2021 Adidas 68 Null
1/31/2022 Nike 110 10%
2/28/2022 Adidas 68 0
... ... ... ...

Would love something that works in Snowflake (SQL: ANSI), but welcome any general ideas.



Sources

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

Source: Stack Overflow

Solution Source