Hi Experts
I have to build a login that will first
1) Pick the rows that have PM compliance banding populated. (Let's call it PM Compliance Record)
2) For that row traverse through all rows which have the same individual item id but PMComplianceBanding is null. (Lets call it non PM compliance records)
3) For the "non PM compliance records" where assignmentplannedstartdate is between AssignmentPlannedStartDate and duration for PM Compliance Record, take the running total for InternalTotalCost and ExternalTotalCost and put that value in the Total cost filed for the PM Compliance Record
| AssignmentPlannedStartDate | IndividualItemID | PMComplianceDays | PMComplianceBanding | InternalTotalCost | ExternalTotalCost | PM Compliance Days (Revised) | Duration | Total Cost |
| 07/09/2020 08:00 | 17NC1099 | 4 | Above Target | 197.7721 | | 4 | 31/12/2020 | |
| 10/01/2020 08:00 | 17NC1099 | -8 | Target | 48 | | -8 | 05/05/2020 08:00 | |
| 17/08/2020 00:01 | 17NC1099 | | | 115.125 | | 1 | | |
| 10/07/2020 00:01 | 17NC1099 | | | 54.75 | | 1 | | |
| 16/10/2020 00:01 | 17NC1099 | | | 46.125 | | 1 | | |
| 07/07/2020 20:49 | 17NC1099 | | | | 210 | 34 | | |
| 26/10/2020 00:01 | 17NC1099 | | | 54.75 | | 1 | | |
| 15/01/2020 00:01 | 17NC1099 | | | 33 | | 0 | | |
| 19/11/2020 00:01 | 17NC1099 | | | 63.375 | | 1 | | |
| 27/07/2020 00:01 | 17NC1099 | | | 589.5 | | 5 | | |
| 06/08/2020 00:01 | 17NC1099 | | | 1041.2128 | | 5 | | |
| 25/11/2020 00:01 | 17NC1099 | | | 80.625 | | 1 | | |
| 07/07/2020 15:20 | 17NC1099 | | | | 2945.9 | 37 | | |
| 05/05/2020 08:00 | 17NC1099 | 0 | Target | 3 | | 0 | 07/09/2020 08:00 | |
| 21/09/2020 00:01 | 17NC1099 | | | 37.5 | | 1 | | |
| 06/02/2020 00:01 | 17NC1099 | | | 80.625 | | 1 | | |
As an example for PM record with assignment planned date of 10/01/2020 and duration of 05/05/2020, I should pick 2 non PM records one with planned start date of 15/01/2020 and other with start date of 06/02/2020. Then take the sum total of cost and put 113.625 ( 30 + 80.625) in the total cost for PM record with assignment planned start date of 10/01/2020 08:00
Any help will be appreciated. I thought of using iterative macros but not sure how will I exit the loop or not have Cartesian product of the records