I am creating a calendar/tracker where a user inputs values into the "Work" column and the spreadsheet should essentially count those cells and the blank cells afterward in order to output values into the "Start Day, End Day, Work Length, and Cycle Length" columns. I'm looking for formulas that can calculate each value in these 4 columns.
My formulas only work in certain scenarios, like if there is only 1 group of values in a column (January and February). They doesn't work for when there are 2 groups of values in a month (March) or when one group starts at the end of the month and continues into the beginning of the next month (March/April).
The April values should be:
Spreadsheet link with current formulas: https://docs.google.com/spreadsheets/d/1WceKBNbyrb2rSCiIfVVpdt9l1fKIpPkqqxPataNHgoY/edit?usp=sharing
You can also try using a Google Sheet Custom Function formula made possible by the Sheet's built-in scripting via Apps Script for a cleaner usage of the sheet formula. Here are the details:
CUSTOM_FUNC(month,array)
This custom formula will return the Start Day, End Day & Work Length automatically. E.g. on your March data, where you have two ranges of Work:
Note: This will also dynamically work on any months & ranges you define. E.g. you can also use
=CUSTOM_FUNC(LEFT(H1,3),I3:I33)
for the February month on cellJ3
.
To add the script below as a custom bound script in your spreadsheet file, you may follow the official guide here.
/**
* Computes the "Start Day", "End Day" & "Work Length".
*
* @param {month,array} input The month value, range.
* @return the "Start Day", "Last Day" & "Work Length".
* @customfunction
*/
function CUSTOM_FUNC(month,array){
var out = [];
for (var arr, i = 0; i < array.length; i++) {
if (array[i] == "") {
arr = null;
} else {
if (!arr) out.push(arr = []);
arr.push([array[i],i+1]);
}
}
var res = out.map(x => x.toString().split(","))
return res.map(y => { return [month+" "+y[1],month+" "+y[y.length-1],(y[y.length-1]-y[1])+1+" days"]});
}
This script was derived from this existing answer to process the range values.