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

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."

Related

Get previous score of user x

Consider the following data set:
A:User | B:Date | C:Score | D:DiffLastResult
1: John 2021-01-01 7
2: Jane 2021-01-01 7
3: James 2021-01-01 8
4: John 2022-01-01 4
5: Jane 2022-01-01 9
6: James 2022-01-01 10
7: John 2022-06-01 10
8: Jane 2022-06-01 5
9: James 2022-06-01 7
Now, I want in column D to have the abs difference between the current score and the previous score (for the given user). So, for instance, user James' last score is 7. Previous score of James was 10, so the delta is minus 3, which should be displayed in cell D9. In cell D6, I want to have a value of 2 (10-8, previous score of James, in context of the score of 2022-01-01).
This list is simplified, for the purpose of asking this question. In my real file, the list of names is unorderded, non-repetitive (not all users have the same amount of scores)
I am using Google Sheets. I have tried using vlookup, lookup, and index/match combinations, but I keep getting the first score of James (instead of the previous one). The list is sorted on date ASC.
Can somebody point me in the right direction? Many thanks.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(
A1:A&COUNTIFS(A1:A, A1:A, ROW(A1:A), "<="&ROW(A1:A))-1, {
A1:A&COUNTIFS(A1:A, A1:A, ROW(A1:A), "<="&ROW(A1:A)), C1:C}, 2, )))

Count number of rows for each type in google spreadsheet

A B C
1 4 Apple
2 5 Orange
3 6 Apple
1 4 Orange
2 4 Apple
3 4 Banana
I want to count each type of column C(if possible also plot it), ie output should be
Apple 3
Orange 2
Banana 1
Just more to a new columns and paste the folloing in its header:
=query(H2:H,"select H, count(H) where H != '' group by H order by count(H) desc label H 'Fruit'", 0)
It is show something like your expection in new two columns beside the original data
As an alternative to the solution already provided, you can make use of UNIQUE and COUNTIF.
Use UNIQUE in order to extract the names for each fruit from the C column
=UNIQUE(C1:C)
Use COUNTIF within an ARRAYFORMULA in order to count the number of times each fruit is present in the C column and later drag it down the E column:
=ARRAYFORMULA(COUNTIF(C1:C,D1))
Reference
UNIQUE Function;
COUNTIF Function.

Sheets: Count Row data Based on Key

Im trying to find a Row based on a value, and count the number of entries (Max 5) in that row.
A
B
C
D
E
F
G
1
John
2
2
5
4
2
Mary
1
3
1
6
7
=COUNTA(B1:GZ) will work if I knew the row for "John",
but im trying to get the row based on a value from another cell ...
Z
10
John
In this case Z10 pseudo: =COUNTA(Find Z10 in Col A, then count entries in Row starting at B to Z)
Any ideas ? Thanks.
Recommendation:
You can try this method
=COUNTA(QUERY(A1:Z, "Select * where A = '"&Z10&"'"))-1
Sample
Sample sheet:
John added on cell Z10
The recommended function added on cell Z11
Result: 4 was the result of COUNTA on the rows B:Z based on Column A that contains the value "John"
NOTE:
You may need to turn on Iterative calculation on your Spreadsheet settings.

How to divide an alphabetical list into 3 column alphabetical list

I have 2 google sheets, one with an alphabetical order names and numbers for each name like: Dean 1 1 1 1, Jacob 2 2 2 2, Kyle 3 3 3 3. I want to transfer all that into another google sheet that has 3 columns, in one is Dean, in one Jacob and in the other one Kyle. I'm trying to a formula that would see a match for their names and place 1 1 1 1 for Dean, 2 2 2 2 for Jacob and 3 3 3 3 for Kyle.
Photos:
You'll find the alphabetical list in one column in the "Project Automation Final Result" in https://docs.google.com/spreadsheets/d/1QrfqAOvIc4XnaJrxk0PMr7pmQp42q2b-V8Bqrzxuchw/edit?usp=sharing
The 3 columns alphabetical list in "Names lists" same link as above.
And I want to insert the Final Result in here https://docs.google.com/spreadsheets/d/1s5yBvEcGFvUiiJTc3K-kQLlCqeOupuGcvqJkZGDmjzY/edit?usp=sharing
Any ideas, suggestions help, thank you for your time.
use this:
=ARRAYFORMULA(IFERROR(VLOOKUP(A6:A,
IMPORTRANGE("1QrfqAOvIc4XnaJrxk0PMr7pmQp42q2b-V8Bqrzxuchw",
"Project Automation Final Result!A:F"), {2,3,4,5,6}, 0)))

Make an equivalent of a "For" loop

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.

Resources