I have in a Google spreadsheet in Col B some values that I would assign a progressive number in Col A.
In particular I would that this progressive number must be assigned to the unique value in Col B.
Desidered Output:
1 | dog
1 | cat
2 | dog
2 | cat
1 | mouse
2 | mouse
3 | dog
3 | cat
...
Assuming the data starts in row 2, see if this works
Arrayformula(if(len(B2:B), countifs(B2:B, B2:B, row(B2:B), "<="&row(B2:B)),))
Related
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.
I'm using a spreadsheet to store highscores. I have one column (Initials [Column D]) and one column (Scores [Column E]). They are already sorted from highest to lowest (dependent upon the Scores). I want to get the first occurrence of all initials and that initials score.
For example if I had this:
|Initials|Scores|
| ABC | 5 |
| NOT | 4 |
| ABC | 2 |
| LOL | 1 |
I want to get this:
|Initials|Scores|
| ABC | 5 |
| NOT | 4 |
| LOL | 1 |
I've been able to get just the names portion with =UNIQUE(D:D), but how would one also get the scores from the next column? I've been trying for a while now, and can't figure it out.
Since the values in E are already sorted, try:
=ArrayFormula(vlookup(unique(filter(D2:D, len(D2:D))), D2:E, {1,2}, 0))
of if you want to use a limited range:
=ArrayFormula(vlookup(unique(D2:D50), D2:E50, {1,2}, 0))
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 would like to COUNTA on a range of cells in a column where I compare if LEFT number is greater than RIGHT number of the cell's value and if the same relation exists in the other column.
In more simple words, for example I do have two column with the person's A and B result predictions of five matches:
| A | B
1 | 2:0 | 2:0
2 | 0:0 | 1:0
3 | 1:2 | 3:0
4 | 1:0 | 0:1
5 | 1:0 | 2:0
And I would like to check the number of rows where columns A and B point the home team as a winner in the same match.
So the result of the function in this case should be 2 as A and B have pointed home team in 2 matches (match 1 and 5).
Thank you in adnavce!
Using the E/F column references in your comment:
=COUNTA(IFERROR(FILTER(E2:E100;LEFT(E2:E100)>RIGHT(E2:E100),LEFT(F2:F100)>RIGHT(F2:F100))))
Note (1): will fail if >=10 goals are predicted (there would be a workaround though).
Note (2): without the IFERROR, when a result of 0 is expected, 1 will be returned.
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)