In google sheets, I have a list of strings (1 per row) where each string is split with 1 character per column, so my sheet looks something like below:
A
B
C
D
E
F
1
F
R
A
N
K
2
P
A
S
S
1
2
I then have this sheet filtered, so Can select only the rows where the first character is F, for example. On another sheet in the same workbook, I have a table of how often each character appears in each column, that looks something like this:
A
B
C
D
E
F
1
Char
Overall
1
2
3
2
A
979
141
304
165
3
B
281
173
69
15
I would like to have this table dynamically update, so that when I filter the first sheet my table shows the frequency only for the strings that meet the filter.
In Excel, this can be accomplished using a combination of SUMPRODUCT and SUBTOTAL but this doesn't work in google sheets. I've seen this done in sheets using helper columns, but I would like the solution to work for a string of an arbitrary number of strings with different lengths without having to change the sheet. Can this be done in Google Sheets?
Thanks!
Hidden cells are assigned with the value 0. One way to solve this is by adding a "helper" column in column A and set all the values in it to 1.
| A | B | C | D | E | F | G
--+--------+------+---+---------+-----+-----+-----
1 | Helper | Char | | Overall | 1 | 2 | 3
--+--------+------+---+---------+-----+-----+-----
2 | 1 | A | | 979 | 141 | 304 | 165
3 | 1 | B | | 281 | 173 | 69 | 15
Now instead of using COUNTIF, use the COUNTIFS formula where the second condition A2:A = 1. For example:
=COUNTIFS([YOUR_CONDITION], A2:A,"=1")
the A column values of hidden rows will calculate as 0, therefore will not be counted.
Related
I have a Google Sheets with the following sheets:
Heroes
A | B | C | D | E
-------------------------------------------------------
The Flash | 5 | 10 | 4 | 82
Jesse Quick | 0 | 2 | 5 | 4
Quicksilver | 1 | 3 | 12 | 2
Kid Flash | 10 | 9 | 7 | 17
Calc
A | B
-------------------------------------------------------
The Flash |
Quicksilver |
I want to match column A in Calc and return the average value of column B to E from Heroes.
So based on the date above, I want Calc should look like this:
A | B
-------------------------------------------------------
The Flash | 25,25
Quicksilver | 4,5
I had this function in Calc:
=AVERAGEIF(Heroes!A:A;B2;Heroes!B:B))
changed to:
=AVERAGEIF(Heroes!A:A;B2;Heroes!B:E))
but this only returns 5 for The Flash and 1 for Quicksilver.
You can try this
=AVERAGE(ARRAYFORMULA( VLOOKUP(A5,A12:E13,{2,3,4,5},FALSE)))
Where A12:A13 refers to HEROES
and A5 refers to Cal
https://docs.google.com/spreadsheets/d/1AEbci4BN8SyYcmpfOELGRQC4wpRqPn-dUoZy5GdkTyM/edit?usp=sharing
For the Flash have: =AVERAGE(Heroes!B1:E1)
For Quicksilver have: =AVERAGE(Heroes!B2:E2)
Using this pattern allows you to get the average of all the Cells in the column of the hero you want. Remember you have to specify the cells, right now you are specifying the whole columns of B-E, when you just want the row of each hero.
Column A (Error.Type) |
(Or any other text) | Column B (Message)
> 1 | #REF! |
> 1 | #REF! | total for error 1 is 2
> 2 | #DIV/0! |
> 2 | "Hello World" | total for error 2 is 2
> 3 | "Foobar" |
> 3 | "Something" |
> 3 | "Else" | total for error 3 is 3
// the number is based on error.type, there are other columns
grand total i need to return 2 + 2 + 3 = 7
=(countif(k:k,k1)>1)) <- this code will return all under conditional formatting
but =count((countif(k:k,k1)>1))) is a circular dependency and i don't know why?
Circular dependency occurs when a formula includes a reference to the cell that holds it. If cell A1, has =A1 the result is the referred error message
=count((countif(k:k,k1)>1)) will return the circular dependency error if it's included on any cell on the K column, on any other column it should work fine.
It sounds like what you are needing is the COUNTIFS() formula. For example, the following function will return a TRUE value for all the rows except the ones with >1 and #REF! in your example. Thus, giving you your uniques.
=COUNTIFS($A:$A,$A1,$B:$B,$B1)=1
Returning this true value for conditional formatting will make w/e you're needing happen on the Range you have it applied. This is assuming whatever value you need in K isn't really needed.
For distinct counts, you can use a helper column (say somewhere in the far right) like this. It will return 1 for each distinct.
| D |
=COUNTIFS(A$1:A1,A1,B$1:B1,B1)
Then this formula will get the total distincts.
=COUNTIF(D:D,1)
In google sheets i use the following formula to get the total of column A in column C for each cell and minus if column B has a value.
C2 =A2
C3 =C2+A3-B3 (Click and drag)
My question is if there is a formula to make column C autocomplete if column A has a value.
--------------------
| A | B | C
--------------------
| 100 | | 100
--------------------
| 150 | | 250
--------------------
| 200 | | 450
--------------------
| 250 | 80 | 620
--------------------
| 300 | | 920
--------------------
This formula should work in cell C2:
=ArrayFormula(IF(ISNUMBER(A2:A250)+ISNUMBER(B2:B250),MMULT(TRANSPOSE(A2:A250)*(ROW(A2:A250) >=TRANSPOSE(ROW(A2:A250))), SIGN(ROW(A2:A250)))-MMULT(TRANSPOSE(B2:B250)*(ROW(B2:B250) >=TRANSPOSE(ROW(B2:B250))), SIGN(ROW(B2:B250))),IFERROR(1/0)))
I've restricted this to the first 250 rows of the sheet but you can amend as necessary. You can calculate the whole column if needed but it will take a while to output if there are a large number of rows
Alternatively, assuming your data starts in row 1, in C1 try this formula:
=ArrayFormula(iferror(if(row(A:A)=1, A1, if(A:A,mmult(transpose(if(transpose(row(A:A))>=row(A:A),A:A+(B:B*-1), 0)),row(A:A)^0),))))
and see if that works ?
Say I have a table:
A, 1
B, 1
C, 2
D, 1
E, 2
How do I view the table grouping by the 2nd column and aggregating by the first with a comma separated concat function ie:
1, "A,B,D"
2, "C,E"
In both defining a pivot table and using the QUERY syntax, it seems that the only aggregation functions available are numerical aggregations like MIN, MAX, SUM, etc. Can I define my own aggregation function?
You have to add a "Calculated Field" to the pivot table, and then select "Summarise by > Custom". This will make the column names in your formula refer to an array of values (instead of a single value). Then you can type a formula like:
= JOIN(", ", MyStringColumn)
More specifically, if you have the following table:
Create a pivot table by going to "Data > Pivot table", with the following configuration. Ensure "Summarize by" is set to "Custom"!
Another option: if the data is in A2:B, then, say, in D2:
=UNIQUE(B2:B)
and then in E2:
=JOIN(",",FILTER(A$2:A,B$2:B=D2))
which is filled down as required.
There are one-formula, auto-expanding solutions, although they get quite convoluted.
You're right, there's no easy way with pivot tables. This though, will do the trick. Inspired by this brilliant answer here.
First, have a header row and run a sort on column A to group by category.
So far, in your example, we have
| A | B
---+-----------+-----------
1 | CATEGORY | ATTRIBUTE
2 | 1 | A
3 | 1 | B
4 | 1 | D
5 | 2 | C
6 | 2 | E
In column C, let's prep the concatenated strings. Start in cell C2 with the following formula, and fill out vertically.
=IF(A2<>A1, B2, C1 & "," & B2)
...looking good...
| A | B | C
---+-----------+-----------+-----------
1 | CATEGORY | ATTRIBUTE | STRINGS
2 | 1 | A | A
3 | 1 | B | A,B
4 | 1 | D | A,B,D
5 | 2 | C | C
6 | 2 | E | C,E
In column D, let's validate the rows we want to select in a later step, with the following formula, starting in cell D2 and filling out. Basically we are marking the final category rows that carry the full concatenated strings.
=A2<>A3
...almost there now
| A | B | C | D
---+-----------+-----------+----------+-----------
1 | CATEGORY | ATTRIBUTE | STRINGS | VALIDATOR
2 | 1 | A | A | FALSE
3 | 1 | B | A,B | FALSE
4 | 1 | D | A,B,D | TRUE
5 | 2 | C | C | FALSE
6 | 2 | E | C,E | TRUE
Now, lets copy column C and D and paste special as values in the same place. Then add a filter on the whole table and filter out column D for the rows labeled TRUE. Now, remove the filter, delete columns B and D and row 1.
| A | B
---+-----------+-----------
1 | 1 | A,B,D
2 | 2 | C,E
Done. Get ice cream. Watch Road House.
I need to SUM all values in the column till the current cell, where the values in a different column are the same.
Example:
------------------------------------------------------
| FIRST | SECOND | SUM |
------------------------------------------------------
| VALUE A | NUMBER 1 | NUMBER 1 |
------------------------------------------------------
| VALUE A | NUMBER 2 | NUMBER 1 + NUMBER 2 |
------------------------------------------------------
| VALUE B | NUMBER 3 | NUMBER 3 |
-------------------------------------------------------
| VALUE B | NUMBER 4 | NUMBER 3 + NUMBER 4 |
-------------------------------------------------------
| VALUE B | NUMBER 5 | NUMBER 3 + NUMBER 4 + NUMBER 5 |
-------------------------------------------------------
The first column has strings, the second numbers and the first holds the results.
Write an if statement to do this. Compare the value of the first column between the current and previous rows, if they have the same value add previous sum and current value together, otherwise the sum becomes the current value.
In code, this would be the formula in C3
=if(exact(A3,A2),C2+B3,B3)