Excel formula to increment every third row by 1 - excel-2010

I want to write a formula that will increment every third row by one while filling the previous rows by the previous number incremented.
Ex.
1
1
1
2
2
2
3
3
3
Thank you for your help,
Oscar

Integer divide of rownumber - row on which we start by 3, plus 1, or
=QUOTIENT(ROW()-1;3)+1

Related

ROW() returns wrong row in array in Google Sheets

With this code
={"Row 1 is row "&ROW();"Row 2 is row "&ROW()}
I get this
Row 1 is row 1
Row 2 is row 1
I assume this is because ROW() returns the row the formula is actually input to. How do I get the correct row number in an array?
EDIT:
What I actually have is this
=ARRAY_CONSTRAIN({
TEXT(DATE(2022,1,1),"MMMM");ARRAYFORMULA(DATE(2022,1,SEQUENCE(DAY(EOMONTH(DATE(2022,1,1),0)))));
TEXT(DATE(2022,2,1),"MMMM");ARRAYFORMULA(DATE(2022,2,SEQUENCE(DAY(EOMONTH(DATE(2022,2,1),0)))));
TEXT(DATE(2022,3,1),"MMMM");ARRAYFORMULA(DATE(2022,3,SEQUENCE(DAY(EOMONTH(DATE(2022,3,1),0)))));
TEXT(DATE(2022,4,1),"MMMM");ARRAYFORMULA(DATE(2022,4,SEQUENCE(DAY(EOMONTH(DATE(2022,4,1),0)))));
TEXT(DATE(2022,5,1),"MMMM");ARRAYFORMULA(DATE(2022,5,SEQUENCE(DAY(EOMONTH(DATE(2022,5,1),0)))));
TEXT(DATE(2022,6,1),"MMMM");ARRAYFORMULA(DATE(2022,6,SEQUENCE(DAY(EOMONTH(DATE(2022,6,1),0)))));
TEXT(DATE(2022,7,1),"MMMM");ARRAYFORMULA(DATE(2022,7,SEQUENCE(DAY(EOMONTH(DATE(2022,7,1),0)))));
TEXT(DATE(2022,8,1),"MMMM");ARRAYFORMULA(DATE(2022,8,SEQUENCE(DAY(EOMONTH(DATE(2022,8,1),0)))));
TEXT(DATE(2022,9,1),"MMMM");ARRAYFORMULA(DATE(2022,9,SEQUENCE(DAY(EOMONTH(DATE(2022,9,1),0)))));
TEXT(DATE(2022,10,1),"MMMM");ARRAYFORMULA(DATE(2022,10,SEQUENCE(DAY(EOMONTH(DATE(2022,10,1),0)))));
TEXT(DATE(2022,11,1),"MMMM");ARRAYFORMULA(DATE(2022,11,SEQUENCE(DAY(EOMONTH(DATE(2022,11,1),0)))));
TEXT(DATE(2022,12,1),"MMMM");ARRAYFORMULA(DATE(2022,12,SEQUENCE(DAY(EOMONTH(DATE(2022,12,1),0)))))},379,1)
This lists all the days of the year with one line added for the month's name. Next to it I have numbers corresponding to each day, and I want to sum all the numbers in each month using the same arrayformula. The problem is that some years are leapyears, so february is dynamic and I need ROW() to tell me what row march starts on but it seems now I need to rethink that formula.
should be:
={"Row 1 is row "&ROW();"Row 2 is row "&ROW()+1}
or:
={"Row 1 is row "&ROW(A1);"Row 2 is row "&ROW(A2)}
but its better this way:
=INDEX({"Row "&ROW(A1:A2)&" is row "&ROW(A1:A2)})

Spreadsheet: Sum of dynamic number of rows

I have a table in my Google Spreadsheet that looks like this :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
4
day 1
8
5
day 2
7
6
day 3
9
7
total
Where I can have multiple "day rows", but I don't know how many. It can be only 1 like it can be 20 "day rows". And I want the "total row" to automatically do a SUM of the "day rows" above.
Result expected :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
15
4
day 1
8
5
day 2
7
6
day 3
9
7
total
24
Where B3 is equal to SUM(B1:B2) and B7 is equal to SUM(B4:B6)
I am trying to do that without the App Script, just using Spreadsheet native functions.
I think I should be using the SUM function or the Query function, but I don't know how to dynamically get the right range. Do you have any idea how to do that ?
Thank you
In your example, column B would be a mixture of constants and formulas. That would require a script to deposit the formulas. However with an extra column, you can avoid scripts. In C2 enter:
=if(A2<>"Total","",sum($B$1:$B1)-sum($C$1:C1))
and copy downwards:
Basically we add column B and subtract any previous Totals in column C.
Another approach is to place the following single array formula in C1:
=ArrayFormula(IF(A:A="",, SUMIF(IF(ROW(A:A),ROW(A:A)), "<="&ROW(A:A),B:B) - SUMIF(IF(ROW(A:A), ROW(A:A)),"<="& VLOOKUP(ROW(A:A)-1, FILTER(ROW(A:A), A:A="total"), 1, TRUE), B:B)))
If you only want to see the values for the "total" rows, change the opening
IF(A:A=""
to
IF(A:A<>"total"
The short version of how it works is that a sum is made of all values up to the current row in B:B, and from that is subtracted any values up to the last listing of the word "total" in A:A.
paste in each cell in B column where A column = total
=INDEX(SUM(IFERROR(1*INDIRECT(ADDRESS(MATCH(INDEX(
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()})-1, ROW()+1, 1),
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()}), 0), 2)&":"&
ADDRESS(ROW()-1, 2)), 0)))

Is there a way to use same field as rows and columns in google sheets to count unique occurrence between columns?

Looking to convert
Task id
John
Jan
Juliet
1
1
1
0
2
1
0
1
3
0
1
1
4
0
0
1
5
0
1
1
6
1
1
0
7
0
1
0
8
1
0
0
9
0
1
1
10
1
1
0
To
John
Jan
Juliet
John
3
1
Jan
3
3
Juliet
1
3
I have set up a new sheet ("Erik Help") in your sample spreadsheet.
In B1:
=SORT(FILTER(Sheet1!B1:1,Sheet1!B1:1<>""))
This simply fills the top row with your names list, sorted alphabetically.
In A2:
=TRANSPOSE(SORT(FILTER(Sheet1!B1:1,Sheet1!B1:1<>"")))
This fills A2 down with the same names list as above, just vertically.
In B2 is the main formula for the grid (which is then dragged over and down):
=ArrayFormula(IF( ($A2="") + (B$1="") + ($A2=B$1),, SUM(MMULT(IF((FILTER(Sheet1!$B$2:$L,Sheet1!$A$2:$A<>"")=1) * (Sheet1!$B$1:$L$1=$A2),1,0), SEQUENCE(COLUMNS(Sheet1!$B$1:$L$1),1,1,0)) * MMULT(IF((FILTER(Sheet1!$B$2:$L,Sheet1!$A$2:$A<>"")=1) * (Sheet1!$B$1:$L$1=B$1),1,0), SEQUENCE(COLUMNS(Sheet1!$B$1:$L$1),1,1,0)))))
The first ( ) + ( ) + ( ) tests three OR conditions. If any is true, the cell will be left blank. This is what allows the formula to be dragged all the way right and down without throwing errors and, in essence, "waiting" for new data from the first two formulas above that it can process.
The rest of the formula is too complex to warrant full explanation (e.g., how MMULT works in detail), this being a volunteer-run site. (Writing the formula took more time than I generally spend in a day on this or other forums.) But here's the gist.
Two grids — each formed by an MMULT (matrix multiplication) — are SUMmed. The first MMULT will produce a grid the same size as the Sheet1 grid, filled with 1 only if two conditions are met: that there was already a 1 in that slot and that the name above matches the name to the right in the "Erik Help" grid. Otherwise, the result for that slot is a zero. The second MMULT forms the same size grid based on the same conditions, only this time it gets a 1 only if there is already a 1 and the name above matches the name above the cell in "Erik Help." These two grids are multiplied, and if the product is a 1, we know that BOTH names had a 1 there. Once SUMmed, we get the count of shared projects for those two names.
As this formula is dragged, cell references not locked with a dollar sign will adjust, so that two different names will be compared by the two MMULT grids.
Because this solution requires comparing arrays with arrays with arrays, I don't currently see how a further array solution is possible, hence the need for the formulas to be dragged. That is, each of these formulas is already jam-packed with array processing.
Again, the formula is currently dragged all the way to Column Z and down to Row 200. However, it only references up to Column L (which is as far as your current names list goes). If your real world application has more names and thus carries over past Column L, the easiest way to change all of the formulas at once is this:
Go to the "Erik Help" sheet (which you can, of course, rename as you like).
Hit Ctrl-H to open the Find/Replace dialog box.
Enter $L in the FIND field and $? in the REPLACE field (where ? will be the new column to which you want the results to extend, e.g., $M or $P, etc.)
Choose "This sheet" from the "Search" drop-down.
Check the box next to "Also search within formulas."
Click the "Replace all" button.
If the data set shrinks or grows again, do the same steps, just changing the old furthest column reference for the new furthest column reference.
Here is a super-simple way of doing it which just changes the pair of columns selected in the countifs as the formula moves across and down by relative addressing:
=countifs(index($B$2:$D,0,row(A1)),1,index($B$2:$D,0,column(A1)),1)
pulled down and across.
Attempt at more general solution.
The question is tagged pivot-table. Although a pivot table approach seems useful, the data is in exactly the wrong format to achieve it. The task would be to transform the data from ones and zeroes to column numbers so
1 1 0 => 1 2
1 0 1 => 1 3
1 1 1 => 1 2, 1 3 and 2 3.
This can be achieved by generating pairs of numbers as follows and performing a lookup in the original data:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
The formulas to generate these sequences are
=ArrayFormula(quotient(mod(sequence(90,1,0),9),3)+1)
and
=ArrayFormula(mod(sequence(90,1,0),3)+1)
(9 because there are 3X3 pairs per row of data, 90 because there are 10 rows of data).
The following generates a lookup for each row of data
=ArrayFormula(quotient(sequence(90,1,0),9)+1)
Putting all this together and wrapping it in a pivot query gives
=ArrayFormula(query({vlookup(quotient(sequence(90,1,0),9)+2,{row(B2:D),B2:D},quotient(mod(sequence(90,1,0),9),3)+2,0)*(quotient(mod(sequence(90,1,0),9),3)+1),
vlookup(quotient(sequence(90,1,0),9)+2,{row(B2:D),B2:D},mod(sequence(90,1,0),3)+2,0)*(mod(sequence(90,1,0),3)+1)},
"select count(Col1) where Col1<>0 and Col2<>0 group by Col1 pivot Col2"))
The formula can be generalised to different numbers of rows and columns.

Google sheets: how to get the last value in the column that has the same value in the previous column?

Name Number
Alpha 5
Echo 2
Charlie 6
Alpha 1
Delta 5
Bravo 7
Alpha 3
Echo 2
Charlie 5
Bravo 2
For example from above, I have names in column A and numbers in column B.
I need a formula to get all the last value of a specific name, for example:
Alpha should return 3,
Bravo should return 2,
Charlie should return 5 etc.
I currently only know how to return the last value in the entire column with:
=INDEX(FILTER(I:I,NOT(ISBLANK(I:I))),ROWS(FILTER(I:I,NOT(ISBLANK(I:I)))))
But it cannot return the last value of a specific value from another column.
Please help, thank you in advance.
Assuming that
The first row is a header row
Name column is A
Number column is B
The specific name whose last number value you want is listed in cell C2
Your formula (in column D2) should be
=INDEX(FILTER(B2:B, A2:A=C2), COUNTA(FILTER(B2:B, A2:A=C2)), 1)
=SORTN(SORT(A1:B10,ROW(A1:A10),0),2^9,2,1,1)
SORT the array in reverse with ROW numbers
SORTN to remove duplicates
Try,
=index(I:I, max(filter(row(I:I), H:H=K2)))

Excel: Count no. of times last value in a row occured

Am sorry am unable to paste the table here as my work laptop security doesn't let me.
I have a row with multiple repetitive values eg columnB to BI containing 2s, 3s, 1s, and 3s again.
The value in last column is 3. I want to count for last how many columns was the value 3 before it changed to something else.
For example: if the row looks like
2 2 3 3 3 1 1 2 2 3 3 2 2 2 2 2 , then the answer I want is 5, because the last value is 2 and it was there for last 5 columns.
I hope it makes sense.
Thank you,
Parul.
You can do it by creating a UDF(User Defined Function) in VBA like this one:
Function CountLast(x As Range, y As Integer)
Dim lColumn, count
lColumn = x.Cells(x.count).Column 'Get last column in range x
count = 0
For i = lColumn To 0 Step -1 'Start with last column and work from right to left
If Cells(1, i).Value <> y Then 'Compare value of each cell with the value provided in y and leave the loop if not found
Exit For
End If
count = count + 1 'Counts how many times the value is found
Next i
CountLast = count 'Returns the counted value
End Function
Then you would use it like this:
=CountLast(B1:BI1,BI1)
For the example data that you provide in your question I used:
=CountLast(A1:P1,P1)
and the resulting answer is 5
What is happening is that the UDF is finding the last cell in the range and then starting there is comparing it to the selected value that you also provide the function and working from right to left (step -1) then it counts as long as they match and in the end returns the counted value.

Resources