Google sheets nested if statement workaround - google-sheets

Link to sheet:
I'm trying to make a scorecard and leaderboard for my golf team, and I need to calculate how many holes a person has finished. The nested if statement in cell J2
=if(G11, 18,
=if(G10, 17,
=if(G9, 16,
=if(G8, 15,
=if(G7, 14,
=if(G6, 13,
=if(G5, 12,
=if(G4, 11,
=if(G3, 10,
=if(C11, 9,
=if(C10, 8,
=if(C9, 7,
=if(C8, 6,
=if(C7, 5,
=if(C6, 4,
=if(C5, 3,
=if(C4, 2,
=if(C3, 1, 0))))))))))))))))))
should accomplish what I need but there are too many functions in the cell to work.
The current function checks the cell where the 18th hole score should be, and if it's there, the player is through 18 holes. If not, it goes to the first nested if and checks the 17th hole score cell, etc...
I know I could do part the function in three different cells and it would work fine, but I'm curious if anyone has any better ideas.
Thanks!

I need to calculate how many holes a person has finished.
I believe what you need is the COUNT function.
=COUNT({G3:G11;C3:C11})
This will give the total number of holes a person has finished.

Below returns an array of all the hole numbers in the first set that has a value against it
=ArrayFormula(E3:E11*(G3:G11<>""))
Below returns the maximum of the hole numbers among all the holes that have a value against them.
=MAX(ArrayFormula(E3:E11*(G3:G11<>"")),ArrayFormula(A3:A11*(C3:C11<>"")))
Broke it up for brevity, but the second one is what I guess you need.

Related

How to change the value of a cell only when everyone has left the house?

I have a sheet consisting of entries that look like this, which I use to keep track of when the members of my family are at home:
DateTime
User
In/Out
5/29 13:00
Mike
In
5/29 13:05
Fred
Out
The rows are added via automation from everyone's phone using IFTTT. I have some flexibility in the format, but not a lot.
I would like to create a cell that changes ONLY when everyone is out of the house. Another IFTTT rule will watch that cell, and when it changes it will start the roomba. So the cell should NOT change if anyone returns home, it should only change if everyone has left.
One way I can think to do this is to set the watched cell to the last timestamp when everyone has left the house. That way, it will only update to a new value when everyone has once again left. Anytime there's a new row, if the status of everyone is Out, it will update the last timestamp.
I'm having a little trouble composing the formulas to keep track of when everyone is Out. This involves looking back through the most recent entries and finding the last time everyone who isn't the current user was out. I figure I can use a filter and a reverse sort and a lookup for every row in the table, but this seems a little complicated and inefficient.
Is there a better way to accomplish what I want?
you could track it like:
=SORTN(SORT(B2:C, ROW(B2:B), 0), 9^9, 2, 1, 1)
and then:
=SUMPRODUCT(INDEX(SORTN(SORT(FILTER({B2:C,
ROW(B2:B)}, B2:B<>""), 3, 0), 9^9, 2, 1, 1)="Out",, 2))=
COUNTUNIQUE(B2:B)
where:
TRUE = everybody out
FALSE = someone in
to get a time when house is empty:
=IF(SUMPRODUCT(INDEX(SORTN(SORT(FILTER({B2:C,
ROW(B2:B)}, B2:B<>""), 3, 0), 9^9, 2, 1, 1)="Out",, 2))=COUNTUNIQUE(B2:B),
INDEX(SORTN(SORT(A2:C, ROW(B2:B), 0), 9^9, 2, 2, 1), 1, 1), "someone home")
I think I got it, many thanks to player0.
The columns in yellow are written by the IFTTT automation. Columns D and E are set to the status of Mike and Carrie, as of that time. D3 is set to:
=INDEX(TRANSPOSE(SORTN(SORT(A$2:C3, ROW(B$2:B3), 0), 9^9, 2, 2, 1)),3)
and filled down for the rest of column D, which also populates E.
Once you have a row with a timestamp and everyone's status, it's a relatively simple thing to pick out the latest row where everyone is out. Cell G4 is set to:
=INDEX(SORT(FILTER(A2:E,D2:D="OUT",E2:E="OUT"),1,FALSE),1,1)
In this example, it shows that the last time everyone was out was on 6/5, which is correct. As more rows are added, the value does not change again until the next time everyone is out, which is important for the automation that watches that cell for changes to know when to start the vacuum.
I am definitely open to more elegant solutions that don't need to drag a formula down column D, but for now this one seems to do the job.

Google sheets - Value of a cell based on the value I input in another cell

I've seen a hundred questions with the same 'title', however I can't figure out the right answer for my problem (or maybe it gets too hard for me).
It's about a Dungeons & Dragons sheet I'm creating for me and my friends.
First a screenshot: http://prntscr.com/khmo43
What I would like is, when I input a number below 'Experience - Cell G2' (like 250), the output in cell F2 would be 1 (since a character is level 1 between 0-299 experience). However, when the experience becomes 300 or higher (between 300-900) the output should be come 2 in Cell F2.
How can I, in this case, automatically have the output in Cell F2 be determined by the value in G2. (So like, IF G2 is between A and B, F2 = C).
I'm extremely sorry if I asked a double question. I've been looking for ages.
Actually not to hard, one I had a chance to think about it. You want to use an index match with a search key as 1.
From the docs,
search_type: 1, the default, causes MATCH to assume that the range is sorted in ascending order and return the largest value less than or equal to search_key.
Because your levels are going to be sorted (I assume) you can put in the min value needed for a character to advance E.g. 0xp is the min value for level 1, 200xp is the min amount needed for level 2, 500xp is the min amount needed for level 3, etc.
=INDEX($E$2:$E$7, MATCH($A$2,$D$2:$D$7, 1))
Good luck with the campaign!

Google Sheets: Listing and counting unique values from multiple cells

I'm looking to list and count unique values from multiple cells. The practical application is to list and count the scenes in a movie that a particular character appears in.
I'm using the following array formula to list the scenes from the data table:
=ArrayFormula(TEXTJOIN(", ",TRUE,IF($B$11:$B$64=E13,$A$11:$A$64,"")))
It will returns something like this (these are the scene numbers):
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4
But I want it to return:
2,3,4
Then to count the unique values I used the following formula:
COUNTUNIQUE(SPLIT(F13,", ",0))
But the problem here is that it returns "1" even when the array formula correctly returns no value (i.e. the character didn't appear in any scene)
Here is the Google Sheet so you can see things in context:
https://docs.google.com/spreadsheets/d/1dwrORFJ508duRP1no7258dqLemujkOjpvA3XmolqtsU/edit?usp=sharing
Any help will be greatly appreciated!
F11:
=ARRAYFORMULA(TEXTJOIN(",",1,UNIQUE(IF(E11=B$11:B,A$11:A,))))
=COUNT(SPLIT(F11,","))
Use UNIQUE() to find unique values before joining them
SPLIT parameter 1 can't be empty, which gives a #VALUE error,Which is counted as 1 with COUNTUNIQUE.Use IFERROR to mask it.(Since we already have unique values, COUNT is simpler)

Ranking Google Sheet Info Uniquely

I am trying to rank the data in one column in my google sheet so that there are no duplicate rankings. I've seen some solutions such as =RANK(A2,$A$2:$A$10)+COUNTIF($A$2:A2,A2)-1, but the problem is that it increments the duplicates based on occurrence in the sheet.
Let's say my data that I'd like ranked is as follows:
1
1
1
2
The rank order would be 2, 3, 4, 1. The problem is, if I change the second entry to 2 (so that my data is now 1, 2, 1, 2) the ranking order becomes 3, 1, 4, 2 instead of 3, 2, 4, 1 like I want. In the original data, the fourth entry was initially the highest and I'd like it to still have the higher rank, but since the formula counts occurrences it gets demoted. Any way to accomplish this?
No, not with native spreadsheet functions. Spreadsheet formulae have no "awareness" of which values were entered most recently.
You would need to resort to Google Apps Script run on an "on edit" trigger.

Is there a SUMMAX or a "No Greater Than" like function in Google Spreadsheets

I have some data that needs to be summed but I would like to set the maximum value at 20, so sum the values but the greatest number that would be returned is 20.
For example, let's say I have three columns labeled A, B, and C. If in row one, the values are 5, 5, 5, the sum should be 15. But if they are 10, 10, 10, I would like the "sum" to show 20 instead of 30.
I have been playing around the the GT() function, but I would not like to create a new column just for comparisons. I would like it all to be in one cell. What would be a simple way of doing this?
=MIN(20, SUM(A1:C1))
maybe? That's what I'd use in Excel...

Resources