edit: must work with blank rows
I have a list of users in Column F and in Row 1 a list of dates.
I want to use ARRAYFORMULA to sum the values from relevant columns per each user. As an example, this sums 4 columns (F,G,H,I) per user:
=ARRAYFORMULA(IF(LEN(F1:F),G1:G+H1:H+I1:I+J1:J,""))
My question is, if it possible to sum for a dynamic number of columns. For example, I'll choose a number (e.g 7, 30...) and it will sum the relevant number of columns.
Can this be done?
Here's a spreadsheet with the above data:
https://docs.google.com/spreadsheets/d/17hyBEF1va4GMYZUFkDxxjJ0pXH2oCccgIaBT79GIsGc/edit#gid=0
In A2 I choose how many columns, and it will sum the relevant number of columns. In C1 I use such a formula to sum 4 columns using ARRAYFORMULA as an example (which is static, not dynamic).
Note that there was a nice solution, but because there is a blank row (#3) it causes the suggested solution to leave the sum for the final row (#7) empty. I'm looking for a solution that will work with blank rows.
There are 3 parameters:
A2: no of cols
G2: top left cell of values
F:F: col of row field (to count number of rows)
=ArrayFormula(MMULT(N(INDIRECT(CELL("address",G2)&":"&ADDRESS(COUNTA(F:F),COLUMN(G2)+A2-1,4))),N(TRANSPOSE(COLUMN(INDIRECT(CELL("address",G2)&":"&ADDRESS(COUNTA(F:F),COLUMN(G2)+A2-1,4)))^0))))
Related
What I want is for a single column (C-L respectively) to count exactly how many cells in their respective row match the same year (from P onward) as the labeled column. So L5(red) will count how many cells from P5-Z5 have "2022" and K8(pink) will count how many cells from P8-Z8 have "2021" in them.
I currently have the number manually entered into each cell, but would like to automate it so it will count the years on its own. Every string of formulas I have tried all come up as error. It was easier to get a second page to count the amount of cells that have a specific word. But now I can't get a single page to count how many cells contain the specific year date in it on its own page.
Here are various logic formulas I've tried. Each of them just comes up as error.
=COUNTIFS(!P5:cc5,(2022))
=COUNTIFS(!p5:cc5,"&2022")
=COUNTIFS(!p5:cc5,\<="2022")
=COUNTIFS(!p5:cc5,"\<=01/01/2022")
=COUNTIFS(!p5:cc5,"\>=01/01/2022",!p5:cc5,"\<01/01/2023")
=COUNTIF(!P5:cc,YEAR(2022))
=COUNTIFS(!P5:cc,"\<="&DATE(2022))
=(COUNTIF(!p5:cc,"\>="01/01/2022)-COUNTIF(!$p$5:$cc,"\>="01/01/2022))
This one is the formula I have for reading the second page to count how many times the specific name shows up. O5 is the cell with the name in it. So I was basing my year counting off this and trying to google my way through it.
=(COUNTIF('Queue List'!$B$3:$D$400,O5))
Sheet layout
As far as I understand you have 10 columns (C-L) that will have to find how many dates in P:CC are in year 2013,2014,2015... right? You can do it like with this formula in C5:
=COUNTIF(ARRAYFORMULA(YEAR($P5:$CC5)),2010+COLUMN())
You're "scanning" the year of the whole row with arrayformula, and then seeing if it matches 2022. In this case I changed 2022 with 2012+COLUMN() so you can drag it or copy and paste to the whole column and the number of column added to 2012 will "calculate" the corresponding year of each column
Another option is to create a whole array with one single formula in C5:
=MAKEARRAY(ROWS(P5:P),10,LAMBDA(r,c,IF(COUNTA(INDEX(P5:CC,r))=0,"",COUNTIF(ARRAYFORMULA(YEAR(INDEX(P5:CC,r))),2012+c))))
Obviously you can adapt it to a specific range. Right now it creates a "rectangle" of 10 columns wide (C-L) and to the bottom of the page (counting the rows between P5 to P (the end of the sheet). "r" and "c" are the number of the row and the column of each cell being calculated (C5 is Row 1, Column 1. D7 is Row 2, Column 3, etc). With INDEX you can select the row to count from the whole range (using that "r" that equals the row), and with c I use the same logic that with the other formula in order to add to 2012+1 in C, 2012+2 in D, 2012+3 in E, etc.
And COUNTA checks first if there is any value in that row, if it doesn't it leaves that row empty (so you won't have a bunch of unnecesary "0"
I am using a filter formula to output multiple results based on a condition. Each result contains 4 columns of data, each result is in a new row. However, I would like all results to be output one after the other (i.e. in one row). The data of each result takes up 4 columns and in the fifth column, the new result starts with 4 columns.
This is how it looks now:
This is how it should look:
To get this dynamically, follow these steps.
1 - in the sheet where you want the results on cell A2 past this formula.
=TRANSPOSE(FLATTEN(QUERY(Data!A2:D," Select * where A is not null ")))
TRANSPOSE because FLATTEN formula outputs a column.
QUERY to remove blank rows.
FLATTEN to convert all values from one or more ranges into a single column.
2 - to make the header dynamic you need to paste this formula in resault sheet in cell A1.
=SPLIT(REPT(JOIN(";",Data!A1:D1)&";",COUNTA(Data!A2:A)),";")
JOIN the header with ; so you can split it with the SPLIT formula after repeating the header rang n time with the REPT formula, to handel how many times the header repeated just use COUNTA to count how many rows are there.
Input example:
Output example:
You first need to use Flatten() to make it a one dimensional array since the spreadsheet data is in a nested array no matter how many rows/columns you have.
Then from here you can just transpose the data so instead of the data going down the rows it will be transposed to go horizontally to the columns.
Try:
=TRANSPOSE(FLATTEN(A2:D))
To combine it with your formula just replace the Range "A2:D" with your current formula.
Result:
References:
Transpose
Flatten
I need an array formula only in column Date_2 with results like on screenshot and that will
insert last day of month depending on Date_0 (if bunch of Color&Fruit&Meal doesn't repeat in table)
insert first minimum date of column Date_1 (if bunch of Color&Fruit&Meal repeats first time) - 1
insert second minimum date of column Date_1 (if bunch of Color&Fruit&Meal repeats second time) - 1
and so on...
Is is possible to solve it with array formula?
I've tried but I can't..
=ArrayFormula(IF(A2:A="","",IF(COUNTIF(B2:B&C2:C&D2:D,B2:B&C2:C&D2:D)>1,INDEX(FILTER(B2:E,E2:E<>""),1,4),EOMONTH(A2:A,0))))
Google Sheets
I'm not quite sure what you need for Date_1 but try this arrayformula in cell F2 for Date_2:
=ARRAYFORMULA({"Date_2";if(IF(B2:B&""&C2:C&""&D2:D<>"",if(A2:A<>"",COUNTIFS(B2:B&"|"&C2:C&"|"&D2:D,B2:B&"|"&C2:C&"|"&D2:D,ROW(A2:A),"<="&ROW(A2:A)),),)=1,eomonth(A2:A,0),)})
I've added a duplicate sheet ("Erik Help") with the following formula in F1:
=ArrayFormula({"Date_2";IF(A2:A="",,IFERROR(VLOOKUP(B2:B&C2:C&D2:D&TEXT(COUNTIFS(B2:B&C2:C&D2:D,B2:B&C2:C&D2:D,ROW(A2:A),"<="&ROW(A2:A))+1,"000"),{B2:B&C2:C&D2:D&TEXT(COUNTIFS(B2:B&C2:C&D2:D,B2:B&C2:C&D2:D,ROW(A2:A),"<="&ROW(A2:A)),"000"),E2:E},2,FALSE)-1,EOMONTH(A2:A,0)))})
This formula creates the header (which you can change within the formula) and all results for Column F.
To lookup the "next instance of the group if there is one," I just wrote the formula to VLOOKUP that grouping plus a text rendering of the COUNTIFS-as-of-that-row-plus-1 for that grouping within a virtual array of each-grouping-plus-unique-count-thus-far in one column and the E2:E data in the next column. For instance, for Row 2, the formula VLOOKUPs redapplepie002
(002 being the text rendition of 001, which is the count of redapplepie as of row 2).
There are 2,827 rows in Column A
Each have a different USD Dollar Value.
Column B Has the same value of 4.99 for the 2,827 rows.
Whats the formula to get the unique sum for the 2,827 rows in column C?
Column D has the same rate of 20.00% for the 2,827 rows
What is the formula to get the grand total?
As I understand you want to add all the total values together.
If you want to have a Grand Total below, you should write just:
=sum(e2:e5) in your e6 cell.
But if you want to add more rows and keep your grand total in the same place, it's useful to have it on top. Like on the picuture:
=sum(e2:e) means that it adds all the cell values found between row 2 and end of this column.
It's also strange that you add 20% in column D. This way you add 0.2 to each value. If this is your intention and insurance costs 20 cents, it's ok. But if you want to add 20% to subtotal value, you should put =c2*1.2 in insurance column.
I just wanted a simple way to number columns or rows in a Google Sheet, and most answers I've found offer many options that are far more complicated than I needed them to be.
Example: I want to number every column in the active sheet, starting with 1 for Column A and counting up by 1, regardless of the content of any other cells on the sheet and if I add columns to the sheet later, I want them to automatically update with the correct column numbers.
Another way is to use SEQUENCE.
So putting =SEQUENCE(99) in A1 would number the first 99 rows, from 1 to 99.
To number columns, just rotate that array, with TRANSPOSE.
So if A1 held =TRANSPOSE(SEQUENCE(26))
that would number columns A to Z with the numbers 1 to 26.
If you want to number both columns and rows,try:
in A1: =SEQUENCE(999), and
in B1: =TRANSPOSE(SEQUENCE(25,1,2))
I realise that this is numbering a specific number of rows, or columns, but I often find that very useful. You could modify this to number all columns or rows by adding some count to determine the total number of rows or columns, and using that in place of the first parameter for the SEQUENCE function.
The simplest way I've found to do this is by putting either of the following formulas in A1:
For numbering rows: =ArrayFormula(ROW(A:A))
And for columns: =ArrayFormula(COLUMN(1:1))
After putting the formula in A1, I'll usually hide the column or row the formula is in so I don't accidentally change or delete it.
If I want the counting to start at 1 on the 2nd, 3rd, or 4th row or column, then adding a -1,-2, or -3 respectively to the end of the formula gets that done.
For example: To number columns starting with 1 in Column C, the formula I put in A1 is =ArrayFormula(COLUMN(1:1)-2).
This may be way more basic than most people on this site are generally looking for, but for some reason it took me an unexpectedly long time to find it/ figure it out, so I thought maybe someone else would find it useful in the future.