Excel formula to return the number of occurrence of a string in a column - excel-2010

I have a Column "Name" as follows and I would like to find the occurrence of a value in the same column in the adjacent Column "Occurrence" as follows: Column "Occurrence" should show the Occurrence of the String next to it till that row
Name Occurrence
Alpha 1
Bravo 1
Alpha 2
Alpha 3
Charlie 1
Charlie 2
Golf 1
Golf 2
Golf 3
Hotel 1
I tried solving this but couldn't succeed, is there is a way to write a formula in column "Occurrence"?

Formulas can be fixed or mutable, or mixed, which is what you want.
The formula should reference the start of the list as a fixed point, but have the end of the list as changable. The $sign is used to tell Excel that a formula used a fixed reference, which will not change when you copy or fill the formula to other cells.
If Name is cell A1 and Occurrence is cell B1
B1 formula = COUNTIF($A$2:A2,A2)
Drag formula down.
The start of the list, $A$2, will stay the same as you copy the formula down. The other two parts will change the row number.

Related

Arrayformula Looping Repetition in Google Sheets

For example I have this set of data below:
Header 1 Header 2
Mouse 5
Elephant 4
What I want to happen is for the word "Mouse" to repeat 5 times and the word "Elephant" to repeat 4 times from top to bottom in Column C.
The output will look something like this:
Header 1 Header 2 Header 3
Mouse 5 Mouse
Elephant 4 Mouse
Mouse
Mouse
Mouse
Elephant
Elephant
Elephant
Elephant
How to do this in Google Sheets?
Thank You
Try the below formula:
Assuming your data range is A2:B and you are entering the formula in C2, if not then you can change the range accordingly
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
REPT(A2:A&",", B2:B), ,999^99), ","))))
Supposing that your "Header 1" is in A1 and the rest of your posted sample is in A:B, place the following formula in C1 of an otherwise empty Column C:
=ArrayFormula({"Header 3"; QUERY(FLATTEN(SPLIT(FILTER(REPT(A2:A&"~",B2:B),A2:A<>""),"~",1,1)),"Select * WHERE Col1 Is Not Null")})
This formula will produce the header text (which you can change within the formula as you like) and all results.
REPT will repeat anything in A2:A (with a tilde appended to the end) B2:B times to form virtual single-cell strings.
FILTER will make sure only occupied rows are included in the REPT function.
SPLIT will split those repetitive strings into separate horizontal cells at those intermittent tildes.
FLATTEN will take all of the results of the SPLIT and form one column from them (spaces and all, since the number of cells per virtual row will differ depending on the requested number of repetitions).
QUERY will purge any empty rows that would have otherwise appeared in the FLATTEN results.
ArrayFormula is necessary because the formula is processing a range as opposed to a single row's data.

Get the corresponding non-empty adjacent cell in a column in Google Sheets

I'm trying to find the formula for column "C" in order to obtain this:
A
B
C
1
blue
flower
blue
2
water
blue
3
sky
blue
4
green
grass
green
5
frog
green
6
yellow
lemon
yellow
7
sun
yellow
I've tried with INDEX and MATCH but I haven't found yet the way to go.
Bonus: a unique formula with ARRAYFORMULA would be very nice for my use case.
Given the exact layout and ranges shown in your post, delete everything from Col C and place this array formula in C1:
=ArrayFormula(IF(B2:B="",,VLOOKUP(ROW(A:A),FILTER({ROW(A:A),A:A},A:A<>""),2,TRUE)))
This will lookup each row number for rows where Col B is not empty within a virtual array of only those row numbers where Col A is not empty paired with the value of Col A, and return the result from the second column of that array. Because the final parameter of VLOOKUP is TRUE, any exact row number searched and not present in the limited virtual array will "fall backward" to the last row number that was occupied.
I guess you are looking for this
=ArrayFormula(if(row(A1:A) <= max(if(not(isblank(B1:B)), row(A1:A))),vlookup(row(A1:A),filter({row(A1:A),A1:A},len(A1:A)),2),))
Another way
=ArrayFormula(if(B2:B="",,lookup(row(A2:A),row(A2:A)/if(A2:A<>"",1,0),A2:A)))

Adding the first digit(s) of a cell ending with specific letter

I have a sheet that has blocks of cells. I add them for a total if they don't contain any letter. Letters signify a specific variable or signifier code for tracking. I also want to add the cell value when a cell has an ending code letter. I've tried SUMIF, Substitute, SumProduct and a few others.
For a while I've used the following which worked till the S value changed to another number than "8" which then gave the wrong sum from the range.
=if(countif(D64:Q64,"*S")=0,"",((countif(D64:Q64,"*S"))*8))
In the cell range I have 5 variable groups ending in a letter (A, H, S, C and R) and one group not ending in any letter.
The formula I use to add the cells not containing a letter but have a value is this
=IF(SUM(AA64,(SUMIF(D65:Q65,"<>")),-(COUNTIF(D65:Q65,">=0")*8))>24,24,(SUM(AA64,(SUMIF(D65:Q65,"<>")),-(COUNTIF(D65:Q65,">=0")*8))))
which adds the table data plus the previous lines table data but does not exceed 24.
H is a set value of 6 and doesn't change.
Does anyone know how to add the value of the cells that contain a specific letter?
N (number)
A
S
C
R
H
8.5
H
8A
2S
9
3C
0.5R
17.5
8
2
3
0.5
6
I'd prefer it be a formula usable in Google Sheets because that is where this data is.
Solution:
You can use this formula below column "N" then drag right until below column "H".
=SWITCH(H$1,"N",SUM($A2:$G2),"H",6,SUM(IFERROR(ARRAYFORMULA(VALUE(LEFT($A2:$G2,FIND(H$1,$A2:$G2)-1))),0)))
This is a combination of three formulas:
If the row above is N, sum A2 to G2. This will ignore all the strings.
If the row above is H, output 6.
Else, get the number to the left of the defined suffix, set all others to 0, and get the sum.
Output:
References:
Extract number from string in Google Sheets
An alternative could be to use
=SUMPRODUCT(A3:G3, isnumber(A3:G3))
to compute the sum of the cells with numbers only, and to use
=sum(filter(substitute($A$3:$G$3, I$2,)+0, regexmatch($A$3:$G$3, I$2)))
under the 'A' and drag to the right
Examples

Sum values of columns into adjacent column

How can I add values in columns (T,U,V) and put the result in each adjacent cell in column S?
Example:
In the top column S cell where you want the result, enter the formula =SUM(T1,U1,V1) replacing row number "1" with the row number on which you are entering the formula.
Then, copy (ctrl-c) the cell containing the formula, and paste it into the cells in column S below.
When you copy & paste a formula, the spreadsheet will automatically adjust the row numbers according to where the formula is pasted.
Note, it will also adjust the Column letters, but in your case this is not relevant, since your Column positions are constant.
See the SUM formula documentation here:
https://support.google.com/docs/answer/3093669
If 14 is in Row1, in S1:
=arrayformula(mmult(T1:V*1,transpose(T2:V2^0)))
Courtesy #Max Makhrov
from here.

Formula to find last value in row and label with Column Top

I'm using Google Spreadsheets. I'll be using this image from a very similar question.
http://i.imgur.com/jqcNW.png [a link]Google Spreadsheet Formula to get last value in a row
Instead of giving the value, I want the Column top to show. So the H column would look something like: 2 1 3 1 4
(The product numbers from Row 1)
If it helps =index(B2:G2;1;counta(B2:G2)) was the answer given to the original question. My values would be words instead of numbers. It'd need to track the last 'Yes' in the row with the column top being dates.
I think this should be easy:
=index($B$1:$G$1;1;counta(B2:G2)) - if you write this to the H2 cell, it should search the "N"th element in the FIRST row ($B$1:$G$1) - where N represents the value of non-empty cells in that row (B2:G2).
You can then populate this H2 formula downwards.
Let me know if this helps.

Resources