Count amount of cells within a specific year - google-sheets

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"

Related

How to get last number in a row on Google Spreadsheets

Spreadsheet
So Basically i'm building a sheet to monitor my NW, my problem is simple, i need the 2023 column to adapt to whatever last number on that row there is, for income i just sum values, but for example the total amount in my bank account is different every month, i just need 2023 column to track that, i update the 31 of each month.
With the formula you can see in the screenshot i have some problem, if i input the number alright, if the value is defined by other formulas it won't show up. Any solutions?
THANKS
Only formula present in the row
Another formula from the comments that seems to not work
I tried =INDEX(X:Y;1;COUNTA(X:Y)) but it won't update if the last number in the row is generated by other formulas.
You can use this formula to find the last value of each row in the range D2:O26. Adapt it as needed!
=BYROW(D2:O26,LAMBDA(e,XLOOKUP(1,INDEX(1/(e<>"")),e,,0,-1)))
Explanation:
BYROW creates an array formula in each row of the range. To each row, here denoted as e, the specified lambda function is applied.
INDEX(1/(e<>"")) returns an array with 1 in places where cell is not empty, and #N/A for empty cells.
XLOOKUP finds the index of the last occurrence (parameter search_mode set to -1) of 1 (first parameter) in the array returned by INDEX and returns corresponding value in the row.
You haven't show what formula in columns Jan-Dec causes you problems. If formula produce values 0 in case you don't what them to count, you can use countif to filter them out:
=INDEX(D13:O13,1,COUNTIF(D13:O13,">0"))
Same as your solution, this only works if columns are filled sequentially - if there are no gaps in each row, e.g. Jan and Mar are filled while Feb is blank.
If you need a more general solution, you may go with series of nested if(isblank(). Here is an example for the first three months, to get an idea:
=INDEX(D13:O13,1,IF(ISBLANK(F13),if(ISBLANK(E13),1,2),3))

Google sheets: inter-sheet formula seems to ignore MATCH criteria... (Copy data from one sheet to another using 1 Match criteria)

I have a Google spreadsheet with 5 tabs (sheets) and I want to copy rows of data from one sheet to another, IF a criteria matches in one of the sheet.
Sheet1 has hundreds of rows of data, across numerous columns. One of the columns lists dates. That column is mostly set to Date format. That date col also uses various Conditional Formatting rules. (I cannot change these or the formatting of this column!).
In sheet5 I have a formula that is supposed to look at sheet1 and find all the rows with a certain date in the date col and then copy the data in that row to a row in sheet5.
It looks like this: =INDEX(sheet1!$A1:$O2002,MATCH($B$1,sheet1!$Q:$Q,0),0)
It kind of works... if I just paste the formula in one cell in sheet5, it finds a row matching the date criteria and copies data over. But if I want to query more of sheet1, by dragging the cell down and find more rows of data to copy over... it just copies all the rows from sheet1 after the initial find... completely ignoring what it's comparing in $B$1 to $Q:$Q... I suspect that what I think it's comparing in MATCH($B$1,sheet1!$Q:$Q,0) may not be what's actually happening, hence the result not matching my expectations...
Here is a screen capture of the sheet I want to copy data from: This sheet is set up and controlled by another party. I CANNOT change data; I CANNOT change data format that is already entered (eg I can't change a col set to Date to Plain Text!) See red notes.
But I can convert Dates in col N to Plain Text in col Q. Column Q is what I am querying/comparing in the formula in the destination sheet (see second screen capture below)
Sheet1 capture: data to copy, criteria date col
In sheet5 I have this formula that queries sheet1:
=INDEX(sheet1!$A1:$O2002,MATCH($B$1,sheet1!$Q:$Q,0),0)
Here is a screenshot of what that formula produces in sheet5
Sheet5 capture: result of using formula
Notice, it kind of works...(when I just paste the formula into my starting cell... it found the one line with the criteria I set) but then if I drag B3 down to query sheet1 more... it just grabs everything, even if $Q:$Q doesn't match the criteria set in B1...
Why?
Any help or clarifying questions are appreciated. Thanks
when dragging you did not lock the rows with $
your formula:
=INDEX(Sheet1!$A1:$Q100, MATCH($B$1, Sheet1!$Q:$Q, 0), 0)
should be:
=INDEX(Sheet1!A$1:Q$100, MATCH($B$1, Sheet1!Q:Q, 0))
coz with your initial formula you just created sort of a "sliding range" by every drag-down. to understand the formula... you are indexing range A1:A100 (from row 1 to row 100) where you narrow it down to just 13th row (MATCH outputs row 13 coz there is the match found. next you drag down and indexing range changes to A2:A101 but the MATCH formula always outputs 13 so 13th row from range A2:A101 is row 14, etc.
anyway, use this in Sheet5!B3 after you delete everything in B3:B range:
=FILTER(Sheet1!A:P, Sheet1!N:N*1=B1*1)

Lookup a value in Column B or C and return key in Column A

I am trying to write a formula that will look for a value in a column, and return the first cell in the row in which it finds the value. So a little like VLOOKUP, but I don't want to search the the first column.
Here is an example dataset:
Room
Monday
Tuesday
DWG 1
S01
S02
DWG 2
S02
S04
DWG 3
S03
S06
DWG 4
S04
S07
Here is what I would like to generate using a formula.
So for the value at B2, I would like it to look up A2 ("S01") in the B column ("Monday") of the top table, and return the value of the cell in the 1st column ("DWG 1").
Ideally it would return nothing or a blank if it doesn't find the exact string in the top table.
Section
Monday
Tuesday
S01
DWG 1
S02
DWG 2
DWG 1
S03
DWG 3
S04
DWG 4
DWG 2
S05
S06
DWG 3
s07
DWG 4
After seeing your in-sheet data and layout, and meeting up with you there live, this is the formula I left for you in the newly added sheet "Erik Help":
=ArrayFormula({"S"&TEXT(SEQUENCE(24,1),"00"),IFERROR(VLOOKUP(FILTER(B1:1,B1:1<>"")&"S"&TEXT(SEQUENCE(24,1),"00"),SPLIT(FLATTEN(FILTER(Sheet1!B1:1,Sheet1!B1:1<>"")&FILTER(INDIRECT("Sheet1!B3:"&ROWS(Sheet1!A:A)),Sheet1!B1:1<>"")&"|"&FILTER(Sheet1!$A3:$A,Sheet1!$A3:$A<>"")),"|"),2,FALSE))})
For the understanding of others, the days of the week (i.e., Monday, Tuesday...) are entered manually as top headers in B1:F1. The header "Section" is entered in A2 with B2:F2 blank. (This is just how the OP wanted it set up.) And the formula is in A3, processing data for A3:F.
The first part of the virtual array just generates the SEQUENCE of section names (S01 - S24) in A3:A26.
The next part looks up every element of one array within another array. The first array is a concatenation of every weekday with every section number from Column A. The second array didn't technically need to be as long as it is in the formula, because we already know exactly how many weekdays, classrooms and sections there are. But it is written to accommodate flexibility, perhaps for future use where four or six days are required, with more or fewer sections.
That second array concatenates every weekday with every section from Sheet1 followed by a pipe symbol and the room for each row from Sheet1. That grid is FLATTENed to one column, and then SPLIT to two columns at the pipe symbol.
Found elements, then, return the class name (which was SPLIT to Column 2 of the virtual VLOOKUP array). If there is no match, IFERROR returns null.
The shorter version possible since we know exactly how many days, sections and rooms we have (and which I left in a new sheet called "Erik Help 2") is this:
=ArrayFormula({"S"&TEXT(SEQUENCE(24,1),"00"),IFERROR(VLOOKUP(Sheet1!B1:F1&"S"&TEXT(SEQUENCE(24,1),"00"),SPLIT(FLATTEN(Sheet1!B1:F1&Sheet1!B3:F17&"|"&Sheet1!A3:A17),"|"),2,FALSE))})
The function you're looking for doesn't exist in Sheets as Vlookup match is performed horizontally from left to right. However, a workaround is to rearrange the columns within the function QUERY and perform a Vlookup to it
Here's an example formula you can use =iferror((vlookup("S01",QUERY(A2:C, "Select B,A",0),2)),"")
This will also leave the cell blank if there are no matching results.
Here's an example of what the end result would look like when I the string "S01" is Vlooked up:

Automatically Number/ Count All Columns or Rows in Google Sheets

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.

Insert duplicate rows (based on one cell-value) in google sheets

So I have this formula that copies rows (with data in col A) into a new range. Column A contains number indicating how many duplicates the row should yield in the result. Also the output rows gets sorted based on the value in column A.
=sort(arrayformula(vlookup(
transpose(split(query(rept(row(D2:D)&" ",A2:A),,9^9)," ")),
arrayformula({row(D2:D),{A2:A,D2:F}}),
{2,3,4,5},
0)),
1,
TRUE)
This is not exectly what I need thou. Instead of having a single value in the cells in column A that indicates how many times the row should be duplicated I need to have a text string like “2,3,5” in every cell in that column, where the individual numbers in the string indicates the position of the row in output (rather than the number of times the row should be copied).
For example, in the output I want the row with the string “2,3,5” to be copied three times. The output should have one of the rows be 2:nd from top, the other 3:rd from top, and the last one the 5:th from top.
If I could have the A2:A part of this range {A2:A,J2:N} instead contain the matching values for split(A2:A) I think it would do what I want.
This is a copy of my google sheet. Hopefully it's possible to understand what it is I'm trying to achieve.
https://docs.google.com/spreadsheets/d/1sp5DRBwFP0-aG-FvjUPKBmyylz0WoPB63ASOOdUGdnI/edit?usp=sharing

Resources