Well I'm using sumif in google sheet and I'm facing this issue. For my case I want to sum all the numbers according with specific parameters, so SUMIF should answer. But the numbers in the table that should be counted are in hours.
As example =SUMIF($B:$B,9,F:F) where 9 the month, summing all the numbers in the column F. But in F the numbers are displayed as 4:00:00 :
| B | F |
| --- | --------- |
| 9 | 4:00:00 |
| 9 | 4:00:00 |
| 9 | 4:00:00 |
using the sumif it was supposed to return 12, the number of hours spend working, but instead returns 0.5. If I put '4' instead of '4:00:00' I can solve the problem. But How I can do the math using the hour format?
Short answer
=ArrayFormula(SUM(FILTER(HOUR(F:F),B:B=9)))
Explanation
Google Sheets use serialized numbers for dates and time, using a day as the unit. The result of the OP formula is 0.5 = 1/2 day = 12 hours.
To have as result 12, first we could use HOUR function but SUMIF requires a range as argument, not arrays.
An alternative solution is to change the format of the cell having the formula use the same format as F:F, so a value of 0.5 will be displayed as 12:00:00.
I was able to find an alternate solution. You can select the output range. And click on Format -> Number -> Duration. It will show in hour format.
Related
I wanted to calculate the difference of numbers that are inputted in a Google sheet row like this:
Row 1: 35 | 37 | 39 | 38 and So on (until last non-empty cell)...
And the output would be:
Row 1 Output: (37-35)+(39-37)+(38-39) = (2+2-1)=3
the suggested formula for this calculation is:
=LAMBDA(rg,SUMPRODUCT(rg-OFFSET(rg,0,-1)))(INDEX(1:1,2):INDEX(1:1,COUNTA(1:1)))
Taking forward to this concept, now I want to calculate days between dates instead of numbers.
something like this (date format:yyy-mm-dd):
Row 1: (blank cell) | 2022-07-06 | (blank cell) | 2022-07-07 | 2022-07-08 and So on (until last non-empty cell)...
Expected Row 1 Output:(2022-07-07-2022-07-06)+(2022-07-08-2022-07-07) = (1+1)=2
I used the above formula but I reckon formula is producing incorrect output because it does not exclude blank cells in between these dates, that's why it gives 44749 an an output,image is also attached:
Here is the how the table looks like in sample sheet in case you want to test it.
Desired Output (No. of Days)
Date1
Date2
Date3
Date4
Date5
Date6
3
2022-07-06
2022-07-07
2022-07-08
2022-07-09
(G2-E2)+(E2-D2)+(D2-B2)
1
2022-07-06
2022-07-07
(G4-C4)
Table is starting from column A to Column G. Any guidance would be much appreciated, thank you.
There are many ways of finding the first and last non-blank cell in a row, but let's use xlookup for the sake of argument:
=ArrayFormula(xlookup(true,(B2:2<>""),B2:2,,0,-1)-xlookup(true,(B2:2<>""),B2:2,,0,+1))
But people just don't believe me when I tell them that (G2-E2)+(E2-D2)+(D2-B2) simplifies to G2-B2. It's basic algebra folks!
Or this is equivalent to my original formula but doesn't lend itself to being written as an array formula:
=index(filter(B2:2,B2:2<>""),count(B2:2))-index(filter(B2:2,B2:2<>""),1)
EDIT
Possible array formula (but could be a bit inefficient):
=iferror(byrow(B2:Z,lambda(r,index(filter(r,r<>""),count(r))-index(filter(r,r<>""),1))))
Also if dates are in ascending order left to right (or more exactly, if the first date is the smallest and the last date the largest), and because min and max ignore blanks, you can simplify the original formula to:
=max(B2:2)-min(B2:2)
or with byrow:
=ArrayFormula(byrow(B2:Z,lambda(r,if(min(r)=0,,max(r)-min(r)))))
I am trying to vlookup a date in a range of text, numbers, dates. vlookup search for number days of a given date, tried to change the number to date, but it does not work.
my formula is =vlookup(date(2022,7,5),A:C,1,false) for the below table. and it should show value text5.
| A B C
---------------------------
1 | text1 7/1/2022 001
2 | text2 7/2/2022 002
3 | text3 7/3/2022 003
4 | text4 7/4/2022 004
5 | text5 7/5/2022 005
It shows #N/A and the Error message was Did not find value '44747' in VLOOKUP evaluation.
I thought it was days and I need to change it to date format. to be =vlookup(to_date(date(2022,7,5)),A:C,1,false). the same problem.
VLOOKUP() will not work in this case, because VLOOKUP() always search on first column and your first column is text field and dates are on second column. So, use INDEX()/MATCH() instead. Try-
=INDEX(A:A,MATCH(DATE(2022,7,5),B:B,0))
Also FILTER(), QUERY() functions will work in your case.
I'm trying to take a column of numbers, parse them in some way, divide them by another column of numbers in the same row, and return the average of each quotient. For example:
| A | B |
|:-:|:-:|
| 6 |210|
| 8 |225|
| 12|240|
I would like to divide A2 by B2, A3 by B3, etc., and then take the average of every quotient and return it (without manually typing in each division). Is there a simple or effective solution to fix this? Very new to Sheets, so over-simplified explanations/answers are highly appreciated :)
You can use Sumproduct to return a single result with the following formula:
=SUMPRODUCT(B1:B3/A1:A3)/COUNTA(B1:B3)
I've got a Google Sheet which holds the results of a monthly competition. The format is
Name | Date | Score
--------------------------------
Alan Smith | 14/01/2016 | 500
Bob Dow | 14/01/2016 | 450
Bob Dow | 16/01/2016 | 470
Clare Allie| 16/01/2016 | 550
Declan Ham | 16/01/2016 | 350
Alan Smith | 10/02/2016 | 490
Bob Dow | 10/02/2016 | 425
Declan Ham | 12/02/2016 | 400
Declan Ham | 12/02/2016 | 390
Clare Allie| 12/02/2016 | 560
I want to do 2 things with this data
I want to create a new sheet which holds the latest 'best' results. For the data presented here that would be
Alan Smith | 10/02/2016 | 490
Bob Dow | 10/02/2016 | 425
Declan Ham | 12/02/2016 | 400
Clare Allie| 12/02/2016 | 560
i.e. The results from February with the 'best' score per person. Here Declan Ham's lower score of '390' was removed.
I want another sheet to hold the tournament ranking. People are ranked by their top 3 monthly scores. i.e. The best score for each person for each month is obtained and the top 3 scores are combined to give their place in the tournament.
So far I've attempted to use Google queries, vlookups, filters to get these new sheets. But, just focusing on 1), the best I've been able to achieve is
=FILTER(Results!$A:$B, MONTH(Results!$B:$B) = MONTH(MAX(Results!$B:$B)))
Which will get me the results from the latest month. But it does not remove duplicates entries by people.
Does anyone have a suggestion for how I can achieve these requirements? Feel like I'm treading water at the moment.
Rather than trying to remove duplicates, you need to identify the maximum score by each person; you can do that by grouping values by person, then aggregating using max(). Here's how that would look, for the month of February 2016:
=query(Results!A1:C,"select A,max(C) where todate(B) > date '2016-2-1' group by A")
Instead of using a fixed value for the start of the latest month, we can get the year and month using spreadsheet formulas, and concatenate our query with them:
=query(Results!A1:C,"select A,max(C) where todate(B) > date '"&year(max(Results!B2:B))&"-"&month(max(Results!B2:B))&"-1' group by A")
That addresses your first question.
Tournament ranking
Your second goal is too complex for a single spreadsheet formula, in my opinion. Here's a way to accomplish it with multiple formulas, though!
The X & Y axes are filled out by spreadsheet formulas. On the X axis (orange), we populate participants names using this in cell A3:
=unique(Results!A2:A)
The Y axis consists of dates (green). These are the start dates of each unique month that there are scores for, calculated using the following formula in cell D2. This results in strings, e.g. 2016-01-1, and that format is specifically required for the later formulas to work.
=TRANSPOSE(SORT(UNIQUE(ARRAYFORMULA(TEXT(Results!B2:B13,"YYYY-MM-1")))))
Here's the formula for cell D3, which will calculate the sum of the 3 highest scores recorded for the user whose name appears in A3, for the month appearing in D2. (Copy & Paste the formula across the full range of participants & months, and it will adjust.)
=sum(query(Results!$A$1:$C,"select C where A='"&$A2&"' and todate(B) >= date '"&B$1&"' and todate(B) < date '"&IF(ISBLANK(C$1),TEXT(TODAY()+1,"yyyy-mm-dd"),C$1)&"' order by C desc limit 3 label C ''"))
Key points about that formula:
The query range needs to used fixed values so it isn't transposed when copied to additional cells. However, it's still open-ended, to absorb additional rows of scores on the "Results" sheet.
Results!$A$1:$C
A WHERE clause is used to select rows from the Results sheet that are for the given participant (A='"&$A2&"') and fall within the month that heads the column (C$1).
...and todate(B) < date '"&IF(ISBLANK(C$1),TEXT(TODAY()+1,"yyyy-mm-dd"),C$1)&"'
The best 3 scores for the month are found by first sorting the above result descending, then limiting the result to 3 rows.
...order by C desc limit 3
Finally, the QUERY headers are suppressed by this little trick, so that we get a single number as the result:
...label C ''
Individual tournament totals appear in column C, with a range SUM across the row, e.g. for cell C3:
SUM(D3:3)
The corresponding ranking in column B is then:
RANK(C3,C$3:C)
Tidy
For simpler copy/paste, you can do some error checking in these formulas, so that they can be placed in the sheet before the corresponding data is - for example, at the start of your season. Using IF(ISBLANK(... or IFERROR(... can be very effective for this.
B3 & down:
=IFERROR(RANK(C3,C$3:C))
C3 & down:
=IF(ISBLANK(A3),"",sum(D3:3))
D3 & rest of field:
=IFERROR(sum(query(Results!$A$1:$C,"select C where A='"&$A3&"' and todate(B) >= date '"&D$2&"' and todate(B) < date '"&IF(ISBLANK(E$2),TEXT(TODAY()+1,"yyyy-mm-dd"),E$2)&"' order by C desc limit 3 label C ''")))
Alternatively for the first part of your question (the latest 'best' results) , in addition to the solution provided by Mogsdad, this should also work.. :-)
=ArrayFormula(iferror(vlookup(unique(A2:A), sort(A2:C, 2, 0, 3, 0), {1,3}, 0)))
EDIT: This formula sorts the table with dates (col B) descending and col C descending and then (ab)uses the fact that vlookup only returns the first match to return the first and last column.
I need some help figuring out some Google Sheets function. I'm trying to look for the value of an adjacent cell based on a key. The problem is that the table has several rows and columns to search for. For example:
| A | B | C | D |
1 | Alpha | 5 | Bravo | 10 |
2 | Charlie | 15 | Delta | 20 |
The list goes on for several more rows and colums. What I'm looking for for example, is when a search use "Delta" as my search key, it will return the value 20 for me. I appreciate your help. Thanks!
Here is the answer I got on the web application community:
https://webapps.stackexchange.com/questions/90198/how-to-get-value-of-adjacent-cell-based-on-key-if-the-table-is-split-into-multi
You can still use vlookup for this, by stacking the lookup tables into one using the array notation {first ; second; third} which means first above second above third. Example:
=vlookup("Delta", {A:B; C:D}, 2, False)
returns 20.
Try:
=offset(lookup("Delta",A1:D2),0,1)
You could use the following:
=ArrayFormula(INDEX($A$1:$D$2,MIN(IF($A$1:$D$2=$G$1,ROW($A$1:$D$2))),MIN(IF($A$1:$D$2=$G$1,COLUMN($A$1:$D$2)))+1))
This could by done in several ways.
Use RegEx
=regexextract(CONCATENATE(A1:D),F6 & "(\d+)")
where F6 is cell with lookup value i.e. "Delta"
Use lookup
=INDEX(A:D,MATCH(LOOKUP(F6,A1:D,A1:A),A1:A),MATCH(F6,INDIRECT(MATCH(LOOKUP(F6,A1:D,A1:A),A1:A)&":"&MATCH(LOOKUP(F6,A1:D,A1:A),A1:A)))+1)
where F6 is cell with lookup value i.e. "Delta", look at example.
MATCH(LOOKUP(F6,A1:D,A1:A),A1:A) is used 3 times, so it could be counted in separate cell.