Nightshifts roster example - Auto fill rest days - google-sheets

Need to implement the following and will need some hints on how to accomplish this for our hospitals' department duty roster.
If a staff member has a night shift (first 3 rows, 2-4) then on the following day a resting day should be automatically set ("//" - symbol) on the day shift rows (row >=5).
That "//" symbol should persist in the cell as long as the member is selected on a night shift row - a user should not be able to change or remove that corresponding "//".
However, when plans change and a member is deselected on the night shift row, the "//" symbol should disappear and it should then be possible to set another value on the following day shift cell.
Here is an example sheet to play around.

A14: ={A1:AF4}
A18: ={A5:B8}
paste this into cell C18 and drag it to the right:
=ARRAYFORMULA(IF(IFERROR(VLOOKUP($A$5:$A$8, B2:B4, 1, 0), )<>"", "//",
REGEXREPLACE(C5:C8, "//", "")))
demo sheet
and then just lock down the resulting table so it couldn't be manipulated
or you may wanna use this instead (based on the level of security)
=ARRAYFORMULA(IF(IFERROR(VLOOKUP($A$5:$A$8, B2:B4, 1, 0), )<>"", "//", {C5:C8}))

Related

How to arrange column data associated with dates into calendar grids (ie. 6x7 array blocks)?

I have this spreadsheet with dates and values in Data!E2:E, i want to transpose all the values in the column E to the calendar in Calendar!B5:H10. I need a formula to transpose all the values from column to rows, but every time it gets to the border of the month it jumps a row.
First day of the week is Sunday, everyday i plan to complete Data!E2:E cells with 'Yes' or 'No' and they should show up in the calendar with green or grey cells. So i can keep track of which things i did.
I have been doing this manually but it takes too long, i also tried inserting the function =TRANSPOSE(Data!E2:E366) in the calendar and modifying the number of the row, its saves a little time but its tedious.
Calendar
Data
delete everything you got and use this in B5. then copy B5 and paste to J5, R5, Z5, B13, J13, etc.
=INDEX(IFNA(VLOOKUP(VLOOKUP(SEQUENCE(6, 7),
{SEQUENCE(DAY(EOMONTH(B4&"/2022", ))+WEEKDAY(B4&"/2022", 1), 1, ),
{IFERROR(ROW(INDIRECT("1:"&WEEKDAY(B4&"/2022", 1)))/0);
SEQUENCE(DAY(EOMONTH(B4&"/2022", )), 1, B4&"/2022")}}, 2, ), Data!$A:$E, 5, )))
demo sheet
https://stackoverflow.com/a/67755777/5632629
In B5, put
=arrayformula(if((row(B5:H10)-row(B4)-1)*7+column(B5:H10)-column(B4)+1>=weekday(date(2022,month(B4&1),1)),
if((row(B5:H10)-row(B4)-1)*7+column(B5:H10)-column(B4)+1-weekday(date(2022,month(B4&1),1))<eomonth(date(2022,month(B4&1),1),0)-date(2022,month(B4&1),1)+1,
vlookup(date(2022,month(B4&1),(row(B5:H10)-row(B4)-1)*7+column(B5:H10)-column(B4)+1-weekday(date(2022,month(B4&1),1))+1),Data!$A$2:$E,5,false),
),
))
Spread (ie. copy & paste cell outside formula editor) the formula to the cells directly below your month names, e.g. J5, R5.
Remove placeholder formulae in your sheet and reset existing text formatting to visualize the results.
You can adapt the above to a single formula by adding a check on whether the corresponding cell for month name for a given cell is empty. It is also possible to combined the 2 if() conditions if you so desire. In addition, I recommend storing the year number of your calendar in a cell and then referring to that cell, instead of hard-coding 2022.

Problem with incrementing of a cell in a google sheets offset formula

I have three formulas, relatively the same, but with a different column for each.
=OFFSET('War Layouts'!$B$2,(ROW(B1)-1)*7,0)
=OFFSET('War Layouts'!$F$2,(ROW(F1)-1)*7,0)
=OFFSET('War Layouts'!$J$2,(ROW(J1)-1)*7,0)
The formula's do exactly what I want, but I want to copy them down my column to repeat the functionality.
When I copy them down, the row number changes to (B4),(F4),(J4), etc. And nothing else increases, which is what I want.
I want the row value to be (B2),(F2),(J2) when I copy down the formula and I just cannot wrack my brain on how to achieve this.
Edit: For additional information, i'm providing a spreadsheet example of what i'm working with.
https://docs.google.com/spreadsheets/d/1Fxc4KcAYlh7vfg7UV0oestKdyuf0LrpvzJmyt0JbAzg/edit?usp=sharing
Essentially I want pull the 'Name' Field, 3 time's a week, every 7 rows.
So day 1 is the B column, Day 2 is F, Day 3 is J.
On the 'Stats' Sheet, is where I have the formula's above. The first 3 row's are correct, but the next three have B4,F4,J4 instead of B2,F2,J2, etc.
This may do what you want, similar to what WOUNDEDStevenJones has described. Since dragging down will normally increment the row numbers in the equations by 1, use INDIRECT to calculate the new row number, based on the current row number divided by 3. The only trick is factoring in your starting row. Here are the three new formulae to replace your existing formulae:
=OFFSET($B$2, ROW( INDIRECT("B" & INT((row()+2)/3))) *7 , 0)
=OFFSET($F$2, ROW( INDIRECT("F" & INT((row()+2)/3))) *7 , 0)
=OFFSET($J$2, ROW( INDIRECT("J" & INT((row()+2)/3))) *7 , 0)
If you put these anywhere on rows 1,2 and 3 (one above the other), they can be dragged down as a group of three. You can test it out by taking just one part, =ROW( INDIRECT("B" & INT((row()+2)/3))), and dragging this down. You'll see it increments the row number by one every three rows.
The only trick is getting the starting value right. If you don't want to place the first formula in row 1, you need to adjust the "+2" amount downwards by 1, for each row you move down. So +1 if starting on row 2, +0 if on 3, -1 if on 4, etc.
Let me know if this helps, or if you need more explanation.

How to use ARRAYFORMULA with OFFSET to previous row without getting circular reference error

Example sheet: https://docs.google.com/spreadsheets/d/14ma-y3esh1S_EkzHpFBvLb0GzDZZiDsSVXFktH3Rr_E/edit?usp=sharing
In column B of ItemData sheet, I have achieved the result I want by copying the formula into every cell in the column, but I want to solve this using ArrayFormula instead.
In column C I have achieved the same result using ArrayFormula. However, for addition, column C is referring to cells in column B, while column B is referring to cells in column B. I.e. every cell in column B is adding 1 to the cell on the row above.
If I select the C3 formula text and paste it into the cell edit field for cell B3 (to not screw up cell references during copy - I know I could make them static references, but this is not my problem), the cell gets an error value of
#REF!
Error
Circular dependency detected. To resolve with iterative calculation, see File > Spreadsheet Settings.
Do note that the additions that need to be done are the same in both cases: Add 1 to the value of the cell on the previous row, so there is no circular reference involved. There is a starting value provided in B2, and cells in B3 and downwards should use the data from the B cell in the previous row.
Also, note that I did try File->Spreadsheet settings and enabling circular reference computation with max 25 items, but this only fills in the first two cells (B3 and B4).
How can I solve this problem? I would prefer having something like ArrayFormula, where the formula only exists in a single cell. But copy-pasting would be acceptable as long as any new rows, inserted in between or added at the bottom, would get the same formula added in column B.
Will matching items always be consecutive? It seems that way since you're comparing each Item cell to the cell above it right in your formula logic. That breaks an [unwritten?] rule of spreadsheet normalization; values' addresses themselves generally should not be treated as data.
IF you're committed to it though, have you considered explicitly using location as a data source? Example:
=ARRAYFORMULA(IFS(
NOT(LEN(A3:A40)),,
ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0)<=VLOOKUP(VLOOKUP(A3:A40,Items!$A$2:$D,2,false),DataPerColor!$A$2:$B,2,false),ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0),
true,
))
Just like your formulas, all that does in English is:
for each row,
if there's no Item, don't output any ItemData,
if the number that belongs in this cell¹ is less than or equal to the lookup, print it,
otherwise, don't output any ItemData
But then what is ¹ "the number that belongs in this cell" and how can we calculate it without using column B? I abuse locations of things to get it. Looking down your row B, each number that appears is just:
this row's number,  minus  
the row where items start [always 3],  minus  
the row number [in just the Item rows] of the first row containing this row's Item
Using the second-to-last ItemC as an example: the first ItemC is the 16th item listing, and the one we're looking up… the "second-to-last ItemC" is in row 21 of the sheet. 21-3-16 = 2 …the number you wanted.
If you can stomach that, it's a single formula and does work according to your specifications.

How do I get Google Sheet Cell References to Change When I Move Rows?

I am use Google Sheets to create set lists for my band.
Each song has columns for "start time," "song length," and "set progress" so we can see how we're doing time-wise during our shows.
My problem: When I drag songs rows up or down to reorder the set list, cell references do not change and I have to copy and paste cell references to get the "start time" and "set progress" to refelect the proper timing.
How do I get the cell references to update when I change the row order? Here's my sample sheet
You want the formulas to always refer to preceding row, even if the rows are rearranged. This can be done with offset. For example, the cell directly above D3 is offset(D3, -1, 0); the cell to the left of D3 is offset(D3, 0, -1). In general it's (cell, number of rows, number of columns).
In D3, enter =offset(D3, -1, 0) + offset(D3, 0, -1) (you can also use SUM() here, though it seems unnecessary) and copy down the column. Importantly, the only named reference here is to the cell itself, everything else is relative to that. So if the rows are interchanged, the structure "cell above", "cell to the left" remains.
Similarly, in B3 one can use =offset(B3, -1, 0) + offset(B3, -1, 1) to refer to the cells directly above and above-and-to-the-right. Or, in a shorter form, =sum(offset(B3, -1, 0, 1, 2)) where the last two parameters are the row/column size of the range being summed.

Reorganize table data to two-column format by repeating the headers and leaving some blank rows

I have a sheet with data organised like this:
I have another sheet in which I want to transpose certain cells of each row, and at the same time, leave 5 rows between the end of the first transposed row and the beginning of the following. Like this:
The real first sheet database has tons of rows, so I'm looking for a way to ease the process, without having to write a formula in each row. It would be great if it could be done by just dragging down the first formulated cell.
This can be done by using modular arithmetics with row numbers. I will describe the solution pretending that I,J columns (which you apparently don't want) aren't there; perhaps you should move them to the right. The formula for Column A would be
=if(mod(row()-1, 14) < 9, indirect("Data!R1C" & mod(row(), 14), False), )
Explanation: The if statement is responsible for skipping 5 rows after each 9; the comma at the end of formula is for this purpose. If the row is in a suitable range, meaning that mod(row(), 14) is one of numbers 1-9, indirect refers to the cell in Data sheet, row 1, column numbered mod(row(), 14).
The formula for column B is similar, with the exception that the row number is also changing.
=if(mod(row()-1, 14) < 9, indirect("Data!R" & floor((row()-1)/14)+2 & "C" & mod(row(), 14), False), )
It refers to Data sheet with column number as above and row number floor(row()/14)+2 - meaning it begins at 2 and increases by 1 every 14 rows.

Resources