Lag function using non-static value for lookup index

Can someone please suggest the ideas to implement lag function using either ifelse or datediff. Want to use lookup index of 365 or 366 depending upon the year. Working with dataset of 7 years with day level granularity. Trying to use lag function to get pervious year/leap-year values.
Thanks in advance !

Hi @slakra, have you tried QuickSight’s period functions? This is a blog might be helpful.