Hello @sarawgia, just to confirm, when you say the max of each month, you mean the single highest instance of revenue in that month. Is that correct? If so, you can slightly edit the suggestion I made in my previous response and that should work.
First, create a date month field with truncDate:
Date Month = truncDate('MM', {calendar_date})
Now, use this as the partition for the maxOver field and the remaining calculation should be unchanged:
sumOver(maxOver(ifelse({Date Month} >=truncDate(‘MM’,addDateTime(-2,‘MM’,{Last Month})) AND {Date Month} <= truncDate(‘MM’,{Last Month}), {total_aws_spend}, NULL), [{Date Month}], PRE_AGG), [], PRE_AGG)
The maxOver value will first check if the date is within the past 3 months, then it will also return the max date for each month. Then, since it is wrapped in a sumOver, it will sum the max values from the last 3 months. This should help you find the value you are looking for.
Also, if you want to see the max values for each month rather than the 3 months combined, you can use the nested max over statement on its own.
maxOver(ifelse({Date Month} >=truncDate(‘MM’,addDateTime(-2,‘MM’,{Last Month})) AND {Date Month} <= truncDate(‘MM’,{Last Month}), {total_aws_spend}, NULL), [{Date Month}], PRE_AGG)
Using a mix of these calculations will be the best way to find the values that you mentioned above. Any time you want to alter the granularity level, you can change the partition field value. I will include some documentation below on these functions as well. Thank you!