Hello SAP Guru’s
I want to define a calculation in data action that should calculate the previous month's average amount and average percentage (%) based on user input. Please refer to the screenshot below.
Here, variable "n" is user input. So, if the user inputs n=3, the logic should give the average of the last 3 months. If the month is September, then the average amount and percentage (%) of June, July, and August should be calculated. The December, January, and February average amount and percentage (%) should be calculated if the month is March.

Anyone who has faced a similar kind of issue knows the workaround in this case. Their comments would be deeply appreciated.
Thank you in advance.
Regards,
Navendu T