I’m trying to build a formula that can achieve the following logic, but I’m struggling to get it working correctly.
I have a data sheet with around 100 project rows. Each row contains a Fab Start date and a Fab Finish date (along with many other fields). Some projects run across two consecutive months.
In my metrics sheet, I have a date column containing the 1st of each month for 12 months. This sheet calculates how many days each project consumes in each month. For projects where the start and finish dates fall within the same month, I already have a working formula:
Code
=SUM(COLLECT( {Workshop Days}, {Start Date}, >= DATE(YEAR(Date@row ), MONTH(Date@row )), {Start Date}, <= DATE(YEAR(Date@row ), MONTH(Date@row ) + 1), {Finish Date}, >= DATE(YEAR(Date@row ), MONTH(Date@row )), {Finish Date}, <= DATE(YEAR(Date@row ), MONTH(Date@row ) + 1)))
Now I’m trying to build a formula that handles projects spanning two consecutive months. Specifically, I need to calculate the number of working days from the Fab Start date to the end of the starting month, so I can allocate the correct number of days to that month (with the remaining days allocated to the following month).
I’m trying to avoid using helper columns because I want this to work for any month in any year without modifying the data sheet.
Here’s the logic I need, in this order:
- If the Fab Start and Fab Finish dates are in the same month:
- If the Fab Start date is today or later:
- Calculate the number of working days from today to the end of the month.
- If the Fab Start and Fab Finish dates are in consecutive months:
- Calculate the number of working days from the Fab Start date to the end of that month.
I want to sum these results across all matching rows, but I’m not sure how to structure the conditions and calculations inside a SUM(COLLECT()) or SUMIFS formula.
Once I can make this work i can apply the same logic to get the days allocated to the ending month. Once the project falls into the current month i will just return the total days remaining.
How can I make this work in Smartsheet?