Sum of row values in Google Spreadsheets - google-sheets

I'm new to Google Sreadsheets syntax, so forgive me if this sounds too trivial. :)
I want to sum up the row values of certain columns in my Google Spreadsheets sheet into a new column.
I'm looking for the right command to do this.
Minimal Working Example
| Column A | Column B | Column C | Column D | Sum B + D |
|----------|----------|----------|----------|-----------|
Row 1| a1 | b1 | c1 | d1 | b1 + d1 |
Row 2| a2 | b2 | c2 | d2 | b2 + d2 |
Row 3| a3 | b3 | c3 | d3 | b3 + d3 |
I want to construct the last column (Sum B + D) with a spreadsheet formula.

In cell E1 add one of the following formulas
=B1 + D1
or
=ADD(B1,D1)
or
=SUM(B1,D1)
Note: The argument separator could be ; (semicolon) instead of , (comma). It depends on the regional setting being used.
Then fill down as necessary.
If you want to avoid to have to do fill down then use the following formula
=ArrayFormula(B1:B3 + D1:D3)

You could use the following if you wnat to sum every row in columns A, D and E
=SUM(A:A,D:D,E:E)
or this if you just want to sum, say, the first 15 rows
=SUM(A1:A15,D1:D15,E1:E15)
Basically SUM can take more than one range parameter!
It may not be what you need right now but SUMIFS are also very useful. This allows you to sum one range based on one or more conditions in other ranges.

Related

How to transpose & split multiple columns and repeat specific cells in a column

I am looking to transpose, split, and keep the correct corresponding Category/Reference Number.
Column A: Category / Reference Number.
Column B: Email (CSV)
| A | B | | A | B |
|001|Email1,Email2,Email3| |001|Email1|
|002|Email4,Email5,Email6| |001|Email2|
| | | |001|Email3|
| | | |002|Email4|
| | | |002|Email5|
| | | |002|Email6|
Here is another post which is similar to what I am looking to accomplish. The only difference is in this post, the OP requested that the formula duplicates data X times. Here is the formula that is used:
=ARRAYFORMULA({TRANSPOSE(SPLIT(CONCATENATE(REPT(B2:B&",", A2:A^2)), ",")),
TRANSPOSE(SPLIT(CONCATENATE(REPT(C2:C&",", A2:A)), ","))})
I have tried modifying this formula by removing the "^2", "A2:A" replacing with a COUNTIF (to determine the number of emails in each row), and keep breaking the formula.
What am I doing wrong?
Here is my sheet.
try:
=ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT('Form Responses'!C2:C, ","))="",,
'Form Responses'!B2:B&"×"&SPLIT('Form Responses'!C2:C, ","))), "×"),
"where Col2 is not null")))

COUNTIF(FILTER(range;condition);criteria) issue in Google Speadsheet

I've a strange result which I cannot explain.
The spreadsheet looks like this (I simplify the data as it's a part of larger sheet):
A | B
-----+---
1 X | Y
2 |
3 |
4 1 |
5 1 |
6 1 |
7 1 |
8 1 |
9 1 |
10 1 |
11 1 |
12 1 |
13 1 |
14 |
...and so empty rows till the end of the sheet.
Cell B2 contains formula:
=COUNTIF(filter(B4:B;$A4:$A = B4:B);"<>0")
Cell B3 contains formula:
=COUNTIF(filter(B4:B13;$A4:$A13 = B4:B13);"<>0")
What I expected to get is 0 in both B2 and B3 cells. Instead of that I receive 0 in B2 and 1 in B3.
The formulas suppose to count number of same non-empty values in column (B2) or part of the column (B3).
Do you have any ideas?
For the same reason that this gives 1:
=countif(na(),"<>0")
The filter in B3 gives no results, so you get "#N/A". When you feed this into COUNTIF, you get 1.
The filter in B2 does give some results (because it succeeds for all the blank cells in cols A & B). But the results are all blanks so you get a count of 0.
Similar approach that I had is this one.
Basically it uses the following formula:
=ArrayFormula({"Count [Erik]";IF(B2:B="","",IFERROR(VLOOKUP(B2:B&"",QUERY({MyTable!B2:B&"",MyTable!C2:C},"Select Col1, COUNT(Col2) Where Col1 Is Not Null And Col2 = 'CriteriaA' Group By Col1"),2,FALSE)))})
(credits to Erik Tyler)

Google Sheets - Query Malfunction

Say I have Sheet 2 data as below:
|----+----|
| A1 | B1 |
|----+----|
| A2 | B2 |
|----+----|
| A3 | 3 |
|----+----|
I want to use query to show it in Sheet 1 with below command:
=query(Sheet2!A:B)
But row 1 and 2 are merged together like the following table
|-------+-------|
| A1 A2 | B1 B2 |
|-------+-------|
| A3 | 3 |
|-------+-------|
If I change the number in B3 from "3" to "B3", then it works just fine. That means if it's a number, query API will not work as expected.
Is it a query API problem or my mistake?
Try using the optional headers argument in QUERY. e.g:
=query(Sheet2!A:B,,1)
Alternatively use:
=index(Sheet2!A:B)
or
={Sheet2!A:B}

google spreadsheets query sql in operator

First I will explain what I am trying to achieve
I have a list with several columns and rows, like this
| a | b | c
-----------------
1 | f1 | 4 | f
2 | f2 | 9 | k
3 | f3 | 1 | x
In another column outside the list I want to write a list with variable size, that contains values of column 'a'.
This list would be for a query like this (suppose that I write the variable list in the column 'd')
=QUERY(A2:D3,"SELECT a, b, c WHERE A IN D")
I think the problem is that I can not use the IN operator from sql
Is there a way to achieve this? The most important part is that I want to write manually a list with variable size for the query?
Thy this formula, in cell E1:
=FILTER(A:C,REGEXMATCH(A:A,JOIN("|",FILTER(D:D,D:D<>""))))
FILTER formula can take any array as condition parameter. REGEXMATCH + JOIN with pipe | will match true when any text from D matches text from A.
This formula is good for one more reason, you may use it as source for further query, like this: =query(my_formula, "select Col1, Col3 where Col2 > 0")

Sort range by order of values in separate column

Given a Google Sheet with the following data:
table 1
| A | B | C
1 | q | w | e
2 | a | s | d
3 | z | x | c
table 2
| A
1 | a
2 | z
3 | q
What formula(s) can sort the rows in 'table 1' according to the stored order of values in 'table 2'?
Edit: How can this be done using a formula in only one cell?
Does this formula work as you want (assuming your tables are named ranges):
=SORT(table1,MATCH(FILTER(A:A,LEN(A:A)),table2,0),1)
See this example Sheet to see it working: https://goo.gl/veSFI4
(1) If you want to sort table 1 as a one-off, add the following in D1 and pull down, then sort on column D:-
=MATCH(A1,table2!A$1:A$3,0)
(2) If you want a table which updates dynamically, in a new sheet (say table 3) enter this in A1 and pull down:-
=table2!A1
and enter this in B1 of the new sheet and pull down and across:-
=INDEX(table1!B$1:B$3,MATCH($A1,table1!$A$1:$A$3,0))
I'm assuming there are no duplicates.

Resources