Make an equivalent of a "For" loop - google-sheets

I'm trying to figure out a way to capture information that's essentially a "For" loop in the programming world. I have one sheet that contains unique names and unique quotes:
SHEET 1
Column A Column B
======== ========
John Hello
Mike Hi
Paul Hey
Joe
And then I have another sheet with multiple names, multiple quotes and a number of times quoted (where 0 times does not exist) and the sheet will continue to add new names and quotes every hour:
SHEET 2
Column A Column B Column C
======== ======== ========
John Hi 2
John Hey 1
Mike Hello 8
Sean Hey 4
Paul Hi 1
Jane Hello 2
John Hello 1
... ... ...
OUTPUT EDIT:
Add the number of times that John, Mike and Paul quoted Hello found in Sheet 2, Column C
Add the number of times that John, Mike and Paul quoted Hi found in Sheet 2, Column C
Add the number of times that John, Mike and Paul quoted Hey found in Sheet 2, Column C
SHEET 3
Column A Column B
======== ========
Hello 9
Hi 3
Hey 1

Create a pivot table from Sheet 2 with ColumnB for Rows, ColumnC for Values and ColumnA for Filter. Adjust filter to select only John, Mike and Paul then lookup Hello, Hey and Hi in Sheet1 from the pivot table with say:
=vlookup(B2,'Pivot Table 1'!A$1:B$3,2,0)
in Sheet1 B2 copied down to suit.

Related

Comparing 2 columns for certain words

=COUNTIF(B4:B, "" & D4:D & "")
So column B4:B will have something like this
Joe Smith, STIM
and column D4:D would have something like this
Joe Smith 10/19/1999 AC
I am trying to make a True False statment in Col G that if column B has Joe Smith and Column D has Joe smith it will say yes or no. This will be a list of names that always change dynamically so one day B4 might be Joe Smith but the next day it could be Jan Doe. Column D will be a list of names in alpha order that changes all the time as well.
I was able to replicate what you need with the example provided by using:
=ArrayFormula(IF(D:D="",,REGEXMATCH(LOWER(D:D),FILTER(LOWER(I:I),I:I<>"")&"\b")))
You can see the results in my testing spreadsheet here.
At the moment I have limited the range from column I but you can just change it so it takes the whole column.
Just one little detail is that with this function you can only have 1 name in each row in the list of names.

Total Sum With Vlookup

I have two spreadsheets with names and times. One is specific session times and on the second sheet, I want to sum up the total times based on each instance from sheet one.
Sheet 1: Session Time
Name | Time
David 5
Mike 2
Daniel 3
David 2
Daniel 8
Sheet 2: Total Time (The one for which I need a forumula)
Name | Total Time
David 7
Mike 2
Daniel 11
I tried a countif and vlookup but I couldn't get it match more than one instance of the name on sheet 1. I also tried this suggested formual from a suggested post but its not summing a second instance of the user name
=ARRAYFORMULA(SUM(ifna(VLOOKUP(A2, 'Sheet 1'!A3:AA16, 5, false))))
A2 = David (On Sheet 2)
Sheet 1'!A3:AA16 = List of names in columns A and all the way to AA is a series of columns with numerical values
5 = the column number from with I want to return the sum for every instance of David (2 in this example with a total of 7)
False = its not sorted
Any help is mucho appriciado!
You can use this formula in your Sheet2!B1:
={"Total Time";arrayformula(if(A2:A<>"",sumif(Sheet1!A1:A,A2:A,Sheet1!B1:B),""))}
Or simply use =arrayformula(if(A2:A<>"",sumif(Sheet1!A1:A,A2:A,Sheet1!B1:B),"")) in Sheet2!B2
Get the sum of the range based on a specific criteria using SUMIF()
Basically, get the sum of Sheet1!B1:B if Sheet1!A1:A matches the current cell being checked in arrayformula A2:A
Output:
This can be accomplished with a simple QUERY, e.g.,
=QUERY('Session Time'!A:B, "Select A, SUM(B) WHERE A Is Not Null GROUP BY A LABEL SUM(B) 'Total Time'")

How to count occurrence in previous rows based on two columns value

I'm trying to count the number of occurrence in previous rows based on two conditional values using Google Sheet.
Let say this is my table :
Row A
Row B
Row C
Row D
1
John
Smith
2
Marty
Butler
3
John
Herbert
4
John
Smith
5
Philip
Rand
6
John
Smith
7
Marty
Butler
Is there a formula that exist that can count those occurrences. The idea is that when I log a new name, if Row B and C already exist it increase the value in Row D by 1 so I would know that it is the nth entry under that name. In my example, Row D would looks like this:
Row A
Row B
Row C
Row D
1
John
Smith
1
2
Marty
Butler
1
3
John
Herbert
1
4
John
Smith
2
5
Philip
Rand
1
6
John
Smith
3
7
Marty
Butler
2
Delete everything in Column D (including the header) and place the following in D1:
=ArrayFormula({"Header";IF(B2:B="",,COUNTIFS(B2:B&C2:C,B2:B&C2:C,ROW(A2:A),"<="&ROW(A2:A)))})
The "Header" text can be edited as you like.
The COUNTIFS reads, in plain English, "Count how many times this first and last name combination has occurred within only the rows up to the current row."

Find a substring in a table and return corresponding value

I have 2 sheets in Google sheets:
Sheet 1
A B
Kindle . Book
McDonald . Restaurant
...
Sheet 2
A B
Kindle Book 1 Book
McDonald Chicago Restaurant
Amazon Kindle Book 2 . Book
...
I want a formula that can populate the column B in Sheet 2 using the table in Sheet 1 based on a substring match.
I have tried various versions of vlookup but not able to get it right.
Ignoring/deleting full stops and surplus spaces, please try:
=index(Sheet1!B:B,match(REGEXEXTRACT(A1,ArrayFormula(textjoin("|",1,Sheet1!A:A))),Sheet1!A:A,0))

Google Sheets, using Countifs to count number of values in a range, and match another cell's value

Working on a Google Spreadsheet, seems to be behaving differently from excel.
This spreadsheet is integrated from a Google form, responses have a date, and a username.
What I am trying to do is count the number of entries between two dates, and submitted by a certain user.
I.e. the sheet looks like this:
A B C
Timestamp User User Names
2/2/2015 Joe Jones Joe Jones
2/12/2015 Steve Ahn Steve Ahn
2/15/2015 Joe Jones
3/3/2015 Joe Jones
3/4/2015 Steve Ahn
I want to count the number of entries for Joe Jones between 2/14/2015 and 3/4/2015 i.e. return the result of 2 here.
Here is what I have so far:
=COUNTIFS(A1:A15,">="&I1,A1:A15,"<="&I2, B2:B15, C1)
But it throws an error "Array Arguments to COUNTIFS are of different size"
Each bit works as a countifs on its own.
Thanks!
The ranges need to be the same size. Change B2 to B1 and it should work.
=COUNTIFS(A1:A15,">="&I1,A1:A15,"<="&I2, B2:B15, C1)
=COUNTIFS(A1:A15,">="&I1,A1:A15,"<="&I2, B1:B15, C1)

Resources