How to iterate cells in a Google sheet formula? - google-sheets

I'm creating a solution to automatically detect conflicts in a schedule created with Google sheets. A "conflict" means that in the same day at the same time different lessons are supposed to have same teacher or to be in the same room. For instance, in the table below groups 1 and 2 are supposed to be in room 2 at the same time, which should be indicated as "conflict".
Monday Tuesday ...
room subject teacher tutor room subject teacher tutor ...
(group1)
09:00-10:00 1 math Smith Black
10:00-10:45 2 science Stones Moore
...
(group2)
10:00-10:45 2 math Smith Taylor
10:55-11:40 1 reading Anderson Harris
...
To check if there are any "same teacher" conflicts, I've added the following formula:
=if(OR(ARRAYFORMULA(D7={D19;D29}));"at this time teacher has another class for _ group";"ok")
However, such solution has some drawbacks.
The main one is: the {D19;D29;...} array is formed manually which is not nice, at least very fragile. If a line is added in the middle of the schedule, most of the checks will break. What I want to do instead is to get the necessary lines by filtering those with the same time in column A and then get cells D to compare.
Another one is, I can't get (and show) the "conflicting" group which this teacher also is supposed to teach (unless I manually create another array, corresponding to {D19;D29;...} which is more manual work), see _ in the formula.
My question is, can I create some form of loop/iterating in Google sheets to deal with this issues in some convenient coding manner? Or may be you'd suggest another approach to this?

There is a tab on the sample sheet called Conflict Finder (Simpler) where you will find this formula in cell G3, and a very similar one in H3.
It counts instances of a common timeslot and teacher name and if it's more than 1, it outputs the word "Conflict"
=ARRAYFORMULA({"Teacher Conflicts";IF(COUNTIFS($A4:$A;$A4:$A;D4:D;D4:D)>1;"Conflict";)})
Once columns with the array formula are created, you can apply conditional formatting with custom formula to highlight the conflicting cells and hide the auxiliary columns. For instance, for range D4:D1000 apply =LEN(G4) to give red background (in fact, range D4:E1000 also works since column H contains conflicts for column E).

Related

Highlight partial/complete matches from 2 columns in google sheets

I have a list of names starting in the first column and a second list starting in the second column. Some of the names are the exact same while others also have a shorter/nickname, include middle names/initials, or a combination of both in the columns. For example:
List One
List Two
John Smith
Anthony Moon
Anthony James Moon
Edward Flores
Edward Flores (Eddie)
John Smith
Angelica C Mary Roach Roach (Angie)
Angelica Roach
I'm trying to use a conditional formatting to highlight cells in the second column to names that are in the first column. However, it only sometimes works because either list could have more of their name. Cells that just include a middle name tend to highlight correctly, but if there are names within parentheses or include an initial, highlighting doesn't seem to work.
Any help would be appreciated.
edit: Example Sheet with manually highlighted cells.
edit 2: I realized that column 2 will always just be first and last name. I'm not sure if this will make things easier or not. Just wanted to include it and I've also updated the example sheet to reflect this.
I duplicated your tab and applied the following conditional formatting custom formula to the range B2:B
=COUNTIF(INDEX(LAMBDA(dist,dist/IF(LEN(A$2:A)>LEN(B2),LEN(A$2:A),LEN(B2)))(MAP(A$2:A,LAMBDA(ζ,INDEX(REDUCE({0,SEQUENCE(1,LEN(ζ))},SEQUENCE(LEN(B2)),LAMBDA(a,c,{INDEX(a,1)+1,SCAN(INDEX(a,1)+1,SEQUENCE (1,LEN(ζ)),LAMBDA(x,y,MIN(INDEX(a,y+1)+1,x+1,INDEX(a,y)+1*(NOT(EXACT(MID(B2,c,1),MID(ζ,y,1)))))))})),LEN(ζ)+1))))),"<="&C$1)
Where C1 is a number that specifies how similar the strings should be in order to be highlighted. If it's 0 it will only highlight the exact matches, if it's 1 it will highlight everything. 0.52 seems to be the sweet spot for the data you provided.
This uses the Levenshtein distance formula developed by Astral.
If the sheet gets too slow you may want to remove those formulas from the conditional formatting, enter them in a helper column and refer to that column instead.

Is there a way to retrieve the right-most non-empty cell in a spreadsheet? Google Sheets [duplicate]

This question already has an answer here:
Looking for the Last Cell that Meets Critera(Horizontally)
(1 answer)
Closed 3 months ago.
This one is a bit of a long shot, but is there a way to determine which cell in a table is the right-most cell that isn't blank? I have a table that has empty cells on purpose; there's nothing to be recorded. I want to retrieve the right-most cell that still has data. For example:
Table 1
Primary Key
Status 1
Status 2
Status 3
Alice
Alpha
Beta
Charlie
Bob
Delta
Carol
Echo
Foxtrot
Eve
Golf
Hotel
Frank
India
Juliet
Kilo
Ideally, the formula would return a list of all the cells it retrieves. In my particular implementation, I don't think it matters what order the returned list is in; this example is more to demonstrate what the table looks like rather than what my data is. It also doesn't matter if it's "attached" to the primary key; the ideal return would be a list that looks like "Charlie, Delta, Foxtrot, Hotel, Kilo." I will be using this generated list for a FILTER function later on, if that changes anything.
Theoretically, it might be possible for me to re-work the data? However, since there are 1000+ entries, I'd rather not have to go through by hand, especially since I will be using this data structure for other formulas later.
EDIT: The values are non-consecutive and are strings; I misrepresented the data in the original example. My apologies.
use:
=IFNA(BYROW(A2:E; LAMBDA(x; LOOKUP(1; INDEX(1/(x<>"")); x))))
Lets say your table is from column A to column H (idk how many colums you need).
You can put in column I this formula (or some column in different sheet):
=INDEX(A2:H2 , ARRAYFORMULA(MAX(COLUMN(A2:H2)*(--(A2:H2<>"")))))
Just cover full colomn I and it will put last value for row 2 in I2, for row 3 in I3 etc.
I cant think of any formula that will join al of that in one cell, but if I do ull update the answer.
Hope this helps.
(Formula is done in US Locale. If you are not in US you can change it in File>Setings>Locale.)

Adding to a cells value based on two other cells

I'm wondering how I would go about adding to a cell based on two other cells.
For example, I'm creating a Google Sheets document to track profit & loss on certain things in an online game I play.
I'll try to explain this as best as possible.
If cell B71 is equal to the string in cell B7, increase the value in cell D71 equal to the number in cell D7.
However, the values will need to be compared to various other things depending on the item required.
For example, the string in cell B7 might change depending on what specific type of item is needed for that day as it does change daily.
I have cells near the bottom of the sheet which list the different type of item which will show the total amount of items used in that month.
I've tried to explain this a little better as requested below
I'm trying to make a spreadsheet that keeps track of the quantity of a specific item I use in a game for a daily task. This task can be done daily, and to keep track of profit & loss, I have created a spreadsheet to keep track of this.
So, each day, there are three different types of items (runes) that can be used in the machine to create an item called 'Vis Wax'. As Runes are cheap, creating the vis wax can generate a good profit. (I love working with data, hense the spreadsheet.
The image above shows what a daily section looks like. I input each type of rune (has to be 3), input the quantity used and the amount each rune is worth to create the total cost under Total.
Further down below, this table has been created
This will keep track of each rune and the amount used during that month.
So with that said, I'm looking for a solution so that if Air rune is entered in ANY of them slots with the QUANTITY used, it'll update that table accordinly (as well as the other runes that are used too). I've tried nested IF statements, but don't seem to have any luck. With the amount of checks that seem to be happening, I can't seem to find a working solution. As Air Rune might be in slot 1 one day, then slot 3 the next day. So it seems each cell in the Quantity Table will need to compare EACH cell in the daily section, to each rune type that can be used.
Hopefully that has explained it a little better.
Spreadsheet Link
https://docs.google.com/spreadsheets/d/1sYLpZJ46IpNk52gxMoJOIZsOCWToLkC4FF83RBncCf0/edit?usp=sharing
I would suggest you to use a different structure and take all the data from one day in one column, something like this:
In this way you will be able to extend the days keeping the formulas in a really simple way. Below, I will explain some useful formulas that you can use to lighten your work:
Day: =text(DAY(B2),"dddd")
Rune type: Check Data validation to create a drop-down list of your rune types
For counting how many runes have you used you can use SUMIFS function. It returns the sum of a range depending on multiple criteria. In your case, you need apply it three time per rune, as you can have the same rune in three different places. You see it with the following image:
The formula is: =SUMIFS($B$8:$H$8,$B$7:$H$7,A25) + SUMIFS($B$12:$H$12,$B$11:$H$11,A25) + SUMIFS($B$16:$H$16,$B$15:$H$15,A25). In this way you only need to write it once and you can fill the rest of the runes just dragging the mouse. If you need more days just change the column H with the last column that you want to take.
I assume that with all this information you can also keep track of your monthly statics easily. I suggest you to create a different sheet for each month.
I hope that my answer was useful, let me know if you have any doubt.
George, I agree with #fullfine, your data structure does not seem ideal for data analysis. And it doesn't seem that efficient for data entry either, with the sideways scrolling (at least on my screen).
But I recognise that you might not want to change it, perhaps having specific reasons for that layout, and having invested time in it. So I offer this formula as an alternative, which basically pulls the needed cells from your existing sheet, and comes up with the totals you'll need.
=QUERY(QUERY({B7:D9;G7:I9;L7:N9;Q7:S9;V7:X9;AA7:AC9;AF7:AH9;
B20:D22;G20:I22;L20:N22;Q20:S22;V20:X22;AA20:AC22;AF20:AH22;
B33:D35;G33:I35;L33:N35;Q33:S35;V33:X35;AA33:AC35;AF33:AH35;
B46:D48;G46:I48;L46:N48;Q46:S48;V46:X48;AA46:AC48;AF46:AH48;
B59:D61;G59:I61;L59:N61},
"select Col1, Col2, Col3*Col2 where Col1 <>'' order by Col1 label Col3*Col2 '' ",0),
"select Col1, sum(Col2), sum(Col3) group by Col1 label sum(Col2) '', sum(Col3) '' ",0)
The same formula can be used for each month, since it always totals all 31 days, even if the month has fewer days.
For your Rune table in the Statistics sheet, you only need the firsts two columns, so you could delete the "sum(Col3)" from the last select statement.
For your smaller financial table, you would take the sum of the Col3 produced by the above formula, ie. the total value of all the runes used. A similar formula would be used to collect the count of the wax produced, its value, and the profit/loss for each day. This would let you complete the financial table.
If you do decide to go with this approach, and want any help with completing the tables, or the formulas, please share your sheet so "anyone can edit it", to make it easier for me to assist you.

How to reflect multiple cells based on specific criteria

Imagine a list on the left filled with employees going down the spreadsheet and headers across the top based categorized on infractions that an employee might violate. this sheet is connected to another sheet which adds a one every time a form is submitted against the employee adding up for the quarter. So employee john smith has across his row would show a 0 if he never committed this infraction and add a 1 to the column each time he did so a row might look like this. John Smith 0 4 5 0 1
The goal is to show the experts name and infraction with how many times this infraction took place removing the infractions that he did not commit so ideally it would look like John Smith 4 5 1 and the header of each number would show what he did.
The goal is to make it much easier to see who did what essentially. There will be over 100 employees and alot of 0's so optically it would look better to distill in order to quickly identify who did what and how many times.
Any ideas?
V lookups and important ranges based on if this is greater than 0 is tedious and does not exactly pull what we want. Essentially omitting the 0s and just showing what an employee has done rather than what they have not done is the goal. All index and match formulas do not seem to specifically answer this problem
simple Index V lookups and matching formulas have been tried
Not able to reflect all three variables (employee/frequency/infraction) while not showing on a master list the people who did not commit the offense
There's a few ways you could set this up. I would set this up so it
Column A = Employee
Column B = Infraction
Column C = 1
Column D = Date
That way you can do a pivot summary and have the employees, with their infractions below their name and the months/years they occurred. Also you can adjust this table as necessary, such as filter by the employee name or by date or by infraction.
The added benefit is you could create a chart with all of these as filters, like cutoff a date range or pick an employee or infraction and it can show a bar graph of all the infractions by month or something like that.
I would agree that listing your data of infractions line by line (as they happen) and using a pivot table would probably be the easiest.
You could also use the AGGREGATE function to pull from a large database as well. This way you could type in an employees name, and a list of all infractions would pop up next to the name (or wherever you would want it) with as much detail as you would like. This way is more complex, but using both a pivot table and the AGGREGATE function might get you the best of both worlds (you could searching infraction types, dates, employees, employee types, and get all the details in the world if wanted).
Hope this helps!
JW

Google Sheets Formula for Pulling Specific Values in Two Ways

I'm trying to do a couple of different things with a spreadsheet in Google and running into some problems with the formulas I am using. I'm hoping someone might be able to direct me to a better solution or be able to correct the current issue I'm having.
First off all, here is a view of the data on Sheet 1 that I am pulling from:
Example Spreadsheet
The first task I'm trying to accomplish is to create a sheet that lists all of these shift days with the date in one column and the subject ("P: Ben" or S: Nicole") in another column. This sheet would be used to import the data via a CSV into our calendar system each month. I tried doing an Index-Match where it used the date to pull the associated values however I found that I had to keep adjusting the formula offsets in order to capture new information. It doesn't seem like Index-Match works when multiple rows/columns are involved. Is there a better way to pull this information?
The second task I am trying to accomplish is to create a new tab which lists all the dates a specific person is assigned too (that way this tab will update in real time and everyone can just look at their own sheet to see what days they are on-call). However, I run into the same problem here because for each new row I have to change the formula to reflect the correct information otherwise it doesn't pull the correct cell when it finds a match.
I would appreciate any and all information/advice on how to accomplish these tasks with the formula combination I mentioned or suggestions on other formulas to use that I have not been able to find.
Thanks in advance!
Brandon. There are a few ways to attack your tasks, but looking at the structure of your data, I would use curly brackets {} to create arrays. Here is an excerpt of how Google explains arrays in Sheets:
You can also create your own arrays in a formula in your spreadsheet
by using brackets { }. The brackets allow you to group together
values, while you use the following punctuation to determine which
order the values are displayed in:
Commas: Separate columns to help you write a row of data in an array.
For example, ={1, 2} would place the number 1 in the first cell and
the number 2 in the cell to the right in a new column.
Semicolons: Separate rows to help you write a column of data in an array. For
example, ={1; 2} would place the number 1 in the first cell and the
number 2 in the cell below in a new row.
Note: For countries that use
commas as decimal separators (for example €1,00), commas would be
replaced by backslashes () when creating arrays.
You can join multiple ranges into one continuous range using this same
punctuation. For example, to combine values from A1-A10 with the
values from D1-D10, you can use the following formula to create a
range in a continuous column: ={A1:A10; D1:D10}
Knowing that, here's a sample sheet of your data.
First Task:
create a sheet that lists all of these shift days with the date in one
column and the subject ("P: Ben" or S: Nicole") in another column.
To organize dates and subjects into discrete arrays, we'll collect them using curly brackets...
Dates: {A3:G3,A7:G7,A11:G11,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
This actually produces two rows rather than columns, but we'll deal with that in a minute. You'll note that, because there are two subjects per every one date, we need to effectively double each date captured.
Dates: {A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
Still with me? If so, all that's left is to (a) turn these two rows into two columns using the TRANSPOSE function, (b) combine our two columns using another pair of curly brackets and a semicolon and (c) add a SORT function to list the dates in chronological order...
=SORT(TRANSPOSE({{A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15};{A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}}),1,TRUE)
Second Task:
create a new tab which lists all the dates a specific person is
assigned too (that way this tab will update in real time and everyone
can just look at their own sheet to see what days they are on-call).
Assuming the two-column array we just created lives in A2:B53 on a new sheet called "Shifts," then we can use the FILTER function and SEARCH based on each name. The formula at the top of Ben's sheet would look like this:
=FILTER(Shifts!A2:B53,SEARCH("Ben",Shifts!B2:B53))
Hopefully this helps, but please let me know if I've misinterpreted anything. Cheers.

Resources