I have two tables in two different Google Sheets documents. The first table has a table with the data, the second table is where I write a formula.
I cannot count the number of rows in which in two different columns in cells two different requirements are met. By two different requirements, I mean two different letters.
Here is an example of a table:
I need to count the rows in which "S" is in column A and "N" is in column B
A link to a table:
https://docs.google.com/spreadsheets/d/1Gx9Oa1d_jtQnxD3Rory-WBeiNw0_3gCqabFEt-VT8yA/edit?usp=sharing
I've tried different combinations:
=COUNTA(QUERY(IMPORTRANGE("1Gx9Oa1d_jtQnxD3Rory-WBeiNw0_3gCqabFEt-VT8y";table!A:B);"Select Column1 Where Column1 = 'S' and Column2 = 'Y'"))
=COUNTIFS(IMPORTRANGE("1Gx9Oa1d_jtQnxD3Rory-WBeiNw0_3gCqabFEt-VT8y";table!A:A);"S";IMPORTRANGE("1Gx9Oa1d_jtQnxD3Rory-WBeiNw0_3gCqabFEt-VT8y";table!B:B);"Y")
Also tried combinations with if and filter.
you need to do it like this:
=COUNTA(IFERROR(QUERY(A:B; "select A where A='S' and B='N'"; 0)))
and then IMPORTRANGE:
=COUNTA(IFERROR(QUERY(
IMPORTRANGE("1Gx9Oa1d_jtQnxD3Rory-WBeiNw0_3gCqabFEt-VT8yA"; "table!A:B");
"select Col1 where Col1='S' and Col2='N'"; 0)))
Related
I got data as follows:
I need a formula that can separate, list and the count each unique word so my output is:
I am pretty new to google sheet formulas, especially combining several together. Thanks in advance.
Suppose the header "Genre" is in A1 with your comma-separated list running down from A2.
Find two empty columns side by side and place the following in the top cell of the leftmost of those two empty columns:
=ArrayFormula(QUERY(FLATTEN(TRIM(SPLIT(FILTER(A2:A,A2:A<>""),","))),"Select Col1, COUNT(Col1) WHERE Col1 Is Not Null GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL Col1 'Genre', COUNT(Col1) 'Total'"))
FILTER will cut null cells from A2:A, leaving you only with populated cells.
SPLIT will split each cell into separate columns at the commas.
TRIM will remove leading spaces that existed after commas.
FLATTEN will form one column from the results of SPLIT.
QUERY will give you the unique names and COUNT for each in highest-to-lowest (DESCending) order of COUNT (with a default of alphabetizing within groups of equal counts) after eliminating any null results of FLATTEN and will assign meaningful headers (LABELs) to each column.
I have 2 tables resulting from the query formulas
formula1
=query(BuchungSystem!A2:AZ,"Select C, F, H, I, J, K, L where Q = "& $B$10)
formula2
=arrayformula({{"MWST ",""}} & QUERY(query(BuchungSystem!A2:AZ,"Select M, N, L where Q = "& $B$10),"SELECT Col1*100, SUM(Col2) GROUP BY Col1, Col3 LABEL SUM(Col2) '' , Col1*100 ''"))
and the result is shown as below
I need to combine 2 ranges since the number of rows in table1 keeps changing and so in table2. Since both are query formulas, they would not expand if the underlying cells have data. To avoid such issues, I am thinking both tables can be joined together with 2 empty lines between tables.
I have tried to join the query result ranges using {formula1;formula2} but it gives me an error since both tables have differing columns. How can I merge the tables one below other?
Mind sharing an example sheet? Here is a quick example of how to include empty columns to make the ranges equal in column size.
={{QUERY(G1:K4,"SELECT G,H,I,J,K")};{"","","","",SUM(QUERY(G1:K4,"SELECT G,H,I,J,K"))}}
If you use 6 columns in one range and only 2 in the next, then you need 4 empty columns in the second {} so their sizes remain the same.
I have 2 columns of data in a Google Sheet. Column1 is unique words or sentences (words are repeated in sentences) and the Column2 is a numeric value next to each (say votes). I am trying to get a list of unique words from Column1 and then the sum of values (votes) from Column2 when the word was present either on its own or in a sentence.
Here is a sample of the data I am working with in Google Sheets:
Term Votes
apple 20
apple eat 100
orange 30
orange rules 40
rule why 50
This is what the end result looks like:
Word Votes
apple 120
eat 100
orange 70
rules 40
rule 50
why 50
The way I am doing it now is quite long and I am not sure if this is the best solution.
Here's my solution:
JOIN values in Column1 using a delimiter " " and then SPLIT them using the same delimiter and then TRANSPOSE them into a column all in one step. This way I have a list of all the words used in Column1 in say Column3.
In Column4 pull out all the UNIQUE values and then do a COUNTIF for the unique values from Column3. This way I am able to get the frequency of each unique word by referencing to the lsit of all words.
In order to get the sum of Votes I have to TRANSPOSE Column4 and then QUERY Column1 and Column2 by using dynamic text in the formula. The formula looks like =QUERY(Column1:Column2, "SELECT SUM(Column2) WHERE Column1 CONTAINS '" & referenceToUniqueWord & "'", 1). The reason I have to transpose first is because the query formula outputs 2 cells of data ie Text: sumColumn1 and Number: 'sum of votes'. Since for one cell of unique word I get two cells of data I am not able to drag the formula down and hence I have to do it horizontally.
I finally get three rows of data after the last step:
One row is just transposed Column4 (all the unique words). Second row is just the text sumColumn2 from using the QUERY formula. And third row is the actual sum of votes, resulting from individual QUERY formulae. I then transpose these rows to columns and to get my final table I VLOOKUP the frequency values arrived at earlier.
This approach is lengthy and prone to errors. Also doesn't work if the list is large and in the initial JOIN I get an error of limit 50,000 reached. Any ideas to make it better are welcome. I know this can be done much easier using Scripts but I'd prefer to have it done using only formulae.
try:
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(
IF(IFERROR(SPLIT(A:A, " "))="",,"♠"&SPLIT(A:A, " ")&"♦"&B:B)
,,999^99)),,999^99), "♠")), "♦"),
"select Col1,sum(Col2)
group by Col1
order by sum(Col2) desc
label sum(Col2)''"))
I have a league table with Column A displaying a list championship entrants.
In the corresponding row are the entrants various race results (points scores). i.e. ColC shows Race 1, ColD Race 2 etc.
I want to sum total, per row (entrant), the 5 largest scores (in Col B)
The following formula works fine entered line by line,
=ArrayFormula(SUM(IFERROR(LARGE($H5:$AE5,{1,2,3,4,5,6}),0)))
However, I want it to be a dynamic array formula that self populates, should new entrants be added. Something like (though this doesn't work):
=arrayformula(If(A2:A<>"",ArrayFormula(SUM(IFERROR(LARGE($H5:$AE5,{1,2,3,4,5,6}),0))),""))
I've been trying to use MMULT, and a few other haphazard ideas, unsuccessfully.
Test sheet can be used here;
https://docs.google.com/spreadsheets/d/18tmKdwAcXoDQrQxSDSnzgK6A5Erj22oSXcxwUt_lq4o/edit?usp=sharing
This should work even with hundreds or thousands of rows. You can find it on the new tab called mk.help
=Arrayformula({"TEST";if(A3:A="",,VLOOKUP(A3:A,query({query(vlookup(SEQUENCE(COUNTA(A3:A)*10,1,0)/10+3,{row(A3:A),A3:A,D3:M},mod(SEQUENCE(COUNTA(A3:A)10,1,0),10){0,1}+{2,3}),"order by Col1,Col2 desc"),Mod(SEQUENCE(COUNTA(A3:A)*10,1,0),10)},"select Col1,Sum(Col2) where Col3<5 group by Col1"),2,0))})
In B3 put this formula:
=arrayformula(query({transpose(split(textjoin(",",false,{left("",row(A3:A5))} & join(",",column(D3:M3)-column(D3))),",",true,false)),sort(split(transpose(split(textjoin("*",false,{row(B3:B5) & "^" & D3:M5}),"*",true,false)),"^",true,false),1,true,2,false)},"Select sum(Col3) where Col1<=4 group by Col2 label sum(Col3) ''"))
but you must modify this for more than row number 5
I have a Google Sheets document with four sheets. In each sheet, there are two columns: first is a name, and second a value.
I need to get the total of the values from the four sheets in a fifth sheet where the names from the four name-columns correspond.
The column with the values is called differently in most sheets.
How can I accomplish this task?
You can use Query + Arrays, like on image below:
Code:
=QUERY({Sheet1!A2:B;Sheet2!A2:B;Sheet3!A2:B;Sheet4!A2:B};
"select Col1,sum(Col2) where Col1 is not null group by Col1 label Col1 'Name',sum(Col2) 'Total'";0)
Explanation:
First: you combine 4 sheets using an Array. Ranges start from row 2 to omit different columns headers:
{Sheet1!A2:B;Sheet2!A2:B;Sheet3!A2:B;Sheet4!A2:B}
Second: Using Query to perform a total. In Query there are some extra operations:
Col1 is not null - for not showing empty rows in totals
label Col1 'Name',sum(Col2) 'Total' - for naming result columns
Syntax may be a little different depending on your local settings, so look at the working copy:
Link to working copy
Is that serves your needs?