Question wrt Lag working dynamically with period type

Hi,

I have a Reporting Period control that changes date aggregation based on Week, Month, Quarter, Year. I’m trying to calculate the PoP percent difference based on the reporting period selected. Tried a lag function but it’s not quite giving me correct values for the previous spend. (See image). Can this be achieved? There are inbuilt periodOverPeriodDifference and PeriodOverPeriod percent difference but can they used with the date aggregation dynamically? Thanks a lot!

The formula for the field Lag_Test_Previous_Val is

lag(
sum({delivered_spend}),
[{Reporting_Period} ASC],1

)

image

I would look at this article!

It should have everything you are looking for!