Loosing my primaryKey during Query({Importhtml1; Importhtml2;...}) in Google Sheets - google-sheets

I need to query up to 50 Sources with dynamic length. Thats why it has to be an all in one command.
The Length of each Source is changing very often. Each Source has RowA as Primarykey. But after the query over all sources, the key isnt unique anymore.
Let´s say my Sources look like this:
SourceA SourceB SourceC
James 5 Jack 3 Jane 5
Steve 3 James 1 Steve 1
Then this Code:
=Query({Importhtml("ScrA";"table";1); Importhtml("ScrB";"table";1); ...})
returns this:
Result:
James 5
Steve 3
Jack 3
James 1
Jane 4
Steve 1
As u can see, i don´t know from which Source "Steve" is coming - but i need to know...
Is there any way to get a result like this (Remember that all Sources have changing Lengths)?
ScrA James 5
ScrA Steve 3
ScrB Jack 3
ScrB James 1
ScrC Jane 4
ScrC Steve 1

you will need to do it like this:
=ARRAYFORMULA(QUERY({
{REGEXREPLACE(INDEX(IMPORTHTML("ScrA"; "table"; 1);;1)&""; ".+"; )&"ScrA"\
IMPORTHTML("ScrA"; "table"; 1)};
{REGEXREPLACE(INDEX(IMPORTHTML("ScrB"; "table"; 1);;1)&""; ".+"; )&"ScrB"\
IMPORTHTML("ScrB"; "table"; 1)}};
"where Col2 is not null"; 0))

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, )))

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

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.

Google Spreadsheet SUMIFs equivalent

I need a SUMIFs equivelent in google spreadsheet. It only has SUMIF, no IFS.
here is my data:
# Salesman Term (Month) Amount
1 Bob 1 1,717.09
2 John 1 634.67
3 Bob 1 50.00
4 Bob 1 1,336.66
5 Bob 1 0.00
6 Bob 1 55.00
7 Bob 300 23,803.97
8 Bob 300 24,483.91
9 Bob 300 20,010.03
10 Bob 300 41,191.62
11 Bob 300 40,493.14
12 Bob 300 10,014.01
13 John 1 100.00
13 John 100 100.00
I want to add everything that BOB sold that the term is equal to or less then 100. I also want to SUM everything that bob sold that the term is greater then 100. Same for John.
You need to use the FILTER function combined with the SUMfunction. In your example with Bob, your function would be like (assuming your data columns is from A to C):
=SUM(FILTER(C:C;A:A="Bob";B:B<=100))
The new Google Spreadsheet, now has the SUMIFS function available.
You can use the following formula:
=SUMIFS(F1:F14,D1:D14, "=Bob",F1:F14, ">=100",E1:E14, "<100")
If you want to perform the calculation for John as well, I can recommend the following:
=QUERY(D1:F14, "SELECT D, SUM(F) WHERE E<100 AND F>=100 GROUP BY D LABEL D 'Who', SUM(F) 'Total'")
See example file I created: SUMIFS on DATA

Resources