Forum Discussion
Sum all values per row until limit is reached with multiple criteria
sturlaws - Thank you so much for all your help! I've put a lot of time into making many improvements and your code is pushing me in the right direction. I am so close and just have one last hurdle that I need to solve with this report that I wanted to see if I could get your help with.
Currently, my calculations are pulling the last 12 months of revenue starting at the max contract end date filtered by account ID and product category but I also need to make the max date filter relative to specific ID# searches.
Here's an example to explain:
Account ID Opportunity ID # Products Start Date End Date Term
1234 DR1234 Analytics 1/1/2020 5/31/2020 5 months
1234 DR2345 Analytics 12/1/2018 11/31/2019 12 months
1234 DR4321 Analytics 4/1/2018 11/31/2018 8 months
Currently, the dashboard will look for the max end date of 5/31/2020 and take 5 months of revenue from the top line and 7 months of revenue from the 2nd line to get a total of 12 months. This is good and this calculation should be the default but let's say I do a search for the first line above by filtering on the opportunity ID# DR1234. If I did this then I'd need the first line to be ignored in the calculation, have the max end date be identified as 11/31/2019, and in this example, I'd be able to pull all of the past 12 months of revenue that I am looking for just from the second line alone.
Another way to say this would be that I need to do the same 12-month calculation but it needs to act relative to a filter/search and begin counting the prior 12 months of revenue, starting on the latest end date of the opportunity ID# prior to the earliest start date of the ID# that I am searching for.
One last piece to this problem:
The above example is easy since if I searched for DR1234 then the lines with ID# DR1234 would be ignored and the 12-month calculation would start 11/31/2019 and would go back until 12/1/2018. However, one of these lines can only be included in this calculation if the latest end date of the prior ID# is <= 6 months from the earliest start date of the new ID# that is being searched for. So, for example, if I searched for DR1234 and the next soonest end date was 3/1/2019 then the calculation should return $0 for revenue because there were no prior ID#s within the past 6 months. But if the next soonest end date, from DR1234's start date, was 7/1/2019 then that line should be included in the calculation and the 12-month look-back period should start on 7/1/2019 and go back until 6/31/2018.
I know this is a lot of information and it is very tricky but please let me know if you need more clarification on this final problem that I am trying to solve and again thank you for all your help!