Array of different sizes - google-sheets

I am using this formula and I am getting some troubles in there:
=ARRAYFORMULA(IF(A2:A="","",IF($B$2:$B>=Helper!$B$2:$B,1,0)))
B2:B Column Main sheet contains almost 30k rows with values and Helper2 B column sheet has only 60 values but the sheet has 1000 rows.
I am checking whether the values in B (Main sheet) are greater or equals to what I have in the Helper B column. But I am only getting the results for the first 1000 rows in the main sheet.
can anyone please tell me what is the workaround for this?
ERROR is: Array arguments to GTE are of different sizes.
Thanks
Here is the link to the Spreadsheet
https://docs.google.com/spreadsheets/d/1hfXCFTp_vLqPFjazM-Vo6-3o8J1td1zpnCJOeK1LBg0/edit#gid=511305173
Main sheet
Helper2 Sheet

The issue is that both sheets have unequal number of rows. (GTE in the error means greater than equal which is the conditional you used)
Easiest fix to eliminate the error is to have the same number of rows from both sheets. If your Main sheet have 30000 and Helper2 have 1000, then add 29000 to your Helper2 sheet.
But if you want to limit your ARRAYFORMULA and only compare until row 1000, then limit the range. Use the formula below:
=ARRAYFORMULA(IF(A2:A1000="","",IF($B$2:$B>=Helper2!$B$2:$B,1,0)))
Or use ARRAY_CONSTRAIN to limit the result of your ARRAYFORMULA
=ARRAY_CONSTRAIN(ARRAYFORMULA(IF(A2:A="","",IF($B$2:$B>=Helper2!$B$2:$B,1,0))), 999, 1)
Limits to 999 rows (since you started at row 2, 1000th row in sheets should be the 999th row of ARRAYFORMULA result)
EDIT:
Try this one:
=arrayformula(if(A2:A="","",if((B2:B <= vlookup(A2:A, Helper2!$A$2:$B, 2)) * (C2:C >= vlookup(A2:A, Helper2!$A$2:$B, 2)) > 0 = TRUE, 1, 0)))
Note:
Your data has issue with your Artem name, not sure why. Thus if Artem is found, blank is returned.
Tried changing all "Artem" to "John" and the formula works seamlessly.

Related

Google Sheets - countif with dynamic range

In sheet1 have a column with a list of IDs, each with a set of statuses:
ID Apr May Jun
1 Load Load Complete
2 Load Complete NA
3 Load Load Load
In a separate sheet, sheet2 I have a list of the IDs and I am trying to show which of those are complete. My thinking is to use countif with a dynamic cell range using the address function:
=countif("'sheet1'!"&address(row(index('sheet1'!$A$1:$A$5,match(A2,'sheet1'!$A$1:$A$5,0),1)),3)&":"&ADDRESS(row(index('sheet1'!$A$1:$A$5,match(A5,'sheet1'!$A$1:$A$500,0),1))+1,26),"Completed")
This formula should find the relevant row for each Id and then check to see whether there are any values of 'Completed' in that row. When combined with an if function, this should give an output of the following in sheet2:
ID Complete
1 Y
2 Y
3 N
But at the moment, it is not registering any as complete as the countif formula is returning a 0 for every row.
Is this because countif cannot handle dynamic ranges using address? If there is a better way to do this, please let me know.
try:
=INDEX(IFNA(VLOOKUP(F2:F, QUERY({A2:A, FLATTEN(QUERY(TRANSPOSE(B2:D),,9^9))},
"select Col1,'Complete' where Col2 contains 'Complete'"), 2, )))
or:
=INDEX(IF(F2:F="",,IFNA(VLOOKUP(F2:F, QUERY({A2:A, FLATTEN(QUERY(TRANSPOSE(B2:D),,9^9))},
"select Col1,'Y' where Col2 contains 'Complete'"), 2, ), "N")))
Given your data, please try the following
=INDEX({A2:A,IF(A2:A="","",
(IF(REGEXMATCH(B2:B&C2:C&D2:D,"Complete")=TRUE,"Y","N")))})
(As always, please adjust ranges to your needs)
Functions used:
INDEX
IF
REGEXMATCH

How to pull data from every third column using QUERY function

I am using this formula but the same formula needs to be applied to every third column. ie: starting from D3:D, G3:G, J3:J, and so on... what is the best way to apply or pull the data from every third column. (data is on the second sheet called Sitemap)
Please advise and help, many many thanks much appreciated!
=query({
'Sitemaps'!D3:D1000},
"Select * where Col1 is not null ")
Adding the sheet link maybe that will be more helpful to understand the situation, "AllURLs" needs to pull all links from Sitemaps into one list
https://docs.google.com/spreadsheets/d/1AWGfA7cHmF3Q2kiX1xkQcoec6H5EPiHUXaiWENMzZkA/edit?usp=sharing
use:
=QUERY({INDIRECT("Sitemaps!"&
ADDRESS(3, (COLUMN($D1)-1)*COLUMN(A1)+1)&":"&
ADDRESS(1000, (COLUMN($D1)-1)*COLUMN(A1)+1))},
"where Col1 is not null")
and drag to the right
update:
use in B3:
=INDEX(IFERROR(REGEXEXTRACT(C3:C,"^(?:https?:\/\/)?(?:www\.)?([^\/]+)")))
use in C3:
=QUERY(FLATTEN(FILTER(IFERROR(Sitemaps!D3:1000), MOD(COLUMN(Sitemaps!D1:1)-1, 3)=0)),
"where Col1 is not null")
Try this:
=FILTER(FILTER(Sitemaps!D3:J,MOD(COLUMN(Sitemaps!D3:J)-4,3)=0),Sitemaps!D3:D<>"")
Just replace :J with whichever column is further to the right in your data set.
This one formula should produce all results, assuming that any rows that have data in Column D also have data in that row of every other included column, and that rows that are null in Column D are also null in that row of every other included column.
MOD is the modulus function. It returns whatever is left after dividing a number by another number. For instance, MOD(7,3) would return 1, because 7 divided by 3 is 6 with 1 left over. The leftover portion is the modulus.
We can apply this to your column numbers, since the ones you want to retrieve are evenly spaced three apart. We just need to start at a baseline of zero. Since Column D has a column number of 4, we can "zero out" that baseline by subtracting 4 from every column number. Only those columns that then are evenly divisible by 3 (i.e., those that, after subtracting 4, have a modulus of 0) are returned.

Why my ArrayFormula is giving error? How do I correct it? (I'm not looking for another Arrayformula as solutions!)

I wanted a ArrayFormula at C1 which gives the required result as shown.
Entry sheet:
(Column C is my required column)
Date Entered is the date when the Name is Assigned a group i.e. a, b, c, d, e, f
Criteria:
The value of count is purely on basis of Date Entered (if john is assigned a on lowest date(10-Jun) then count value is 1, if rose is assigned a on 2nd lowest date(17-Jun) then count value is 2).
The value of count does not change even when the data is sorted in any manner because Date Entered column values is always permanent & does not change.
New entry date could be any date not necessarily highest date (If a new entry with name Rydu is assigned a on 9-Jun then the it's count value will become 1, then john's (10-Jun) will become 2 and so on)
Example:
After I sort the data in any random order say like this:
Random ordered sheet:
(Count value remains permanent)
And when I do New entries in between (Row 4th & 14th) and after last row (Row 17th):
Random Ordered sheet:
(Doesn't matter where I do)
I already got a ArrayFormula which gives the required result:
={"AF Formula1"; ArrayFormula(IF(B2:B="", "", COUNTIFS(B$2:B, "="&B2:B, D$2:D, <"&D2:D)+1))}
I'm not looking for another Arrayformula as solutions. What I want is to know what is wrong in my ArrayFormula? and how do I correct it?
I tried to figure my own ArrayFormula but it's not working:
I got Formula for each cell:
=RANK($D2,FILTER($D$2:$D, $B$2:$B=$B2),1)
I figured out Filter doesn't work with ArrayFormula so I had to take a different approach.
I took help from my previous question answer (Arrayformula at H3) which was similar since in both cases each cell FILTER formula returns more than 1 value. (It was actually answered by player0)
Using the same technique I came up with this Formula which works absolutely fine :
=RANK($D2, ARRAYFORMULA(TRANSPOSE(SPLIT(VLOOKUP($B2, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ","))), 1)
Now when I tried converting it to ArrayFormula:
($D2 to $D2:$D & $B2 to $B2:$B)
=ARRAYFORMULA(RANK($D2:$D,TRANSPOSE(SPLIT(VLOOKUP($B2:$B, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ",")), 1))
It gives me an error "Did not find value '' in VLOOKUP evaluation", I figured out that the problem is only in VLOOKUP when I change $B2 to $B2:$B.
I'm sure VLOOKUP works with ArrayFormula, I fail to understand where my formula is going wrong! Please help me correct my ArrayFormula.
Here is the editable sheet link
if I understand correctly, you are trying to "rank" B column based on D column dates in such way that dates are in theoretical ascending order so if you randomize your dataset, the "rank" of each entry would stay same and not change based on the randomness you introduce.
therefore the correct formula would be:
={"fx"; INDEX(IFNA(VLOOKUP(B2:B&D2:D,
{INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1),
IFERROR(1/(1/COUNTIFS(
INDEX(SORT(B2:D, 3, 1),,1),
INDEX(SORT(B2:D, 3, 1),,1), ROW(B2:B), "<="&ROW(B2:B))))}, 2, 0)))}
{"fx"; ...} array of 2 tables (header & actual table) under each other eg. ;
outer shorter INDEX or longer ARRAYFORMULA (doesnt matter which one) is needed coz we are processing an array
IFNA for removing possible #N/A errors from VLOOKUP function when VLOOKUP fails to find a match
we VLOOKUP joint B and D column B2:B&D2:D in our virtual table {} and returning second 2 column if there is an exact match 0
our virtual table {INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1), ...} we VLOOKUP from is constructed with 2 columns next to each other eg. ,
we are getting the first column by creating an array of 2 columns {B2:B&D2:D, D2:D} next to each other where we SORT this array by date/2nd column 2, in ascending order 1 but all we need after sorting is the 1st column so we use INDEX where we bring all rows ,, and the first column 1
now lets take a look on how we getting the 2nd column of our virtual table by using COUNTIFS which will mimic the "rank"
IFERROR(1/(1/ is used to remove all zero values from the output (all empty rows would have 0 in it as the "rank")
under COUNTIFS we put 2 pairs of arguments: "if column is qual to column" and "if row is larger or equal to next row increment it by 1" ROW(B2:B), "<="&ROW(B2:B))
for "if column is qual to column" we do this twice and use range B2:D and sort it by date/3rd column 3 in ascending order 1 and of this we again need only the 1st column so we INDEX it and return all rows ,, and first column 1
with this formula you can add, remove or randomize your dataset and you will always get the right value for each of your rows
as for why your formula doesnt work... to not get #N/A error for vlookup you would need to define the end row of the range but still, the result wont be as you would expect coz formula is not the right one for this job.
as mentioned there are functions that are not supported under AF like SUM,AND,OR and then there are also functions which work but in a different way like IFS or with some limitations like SPLIT,GOOGLEFINANCE,etc.
I have answered you on the tab in your shared sheet called My Practice thusly:
You cannot split a two column array as you have attempted to do in cell CI2. That is why your formula does not work. You can only split a ONE column array.
I understand you are trying to learn, but attempting to use complicated formulas like that is going to make it harder I'm afraid.

Array formula with filter and index values depending on countif

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).

Lookup in array, return same row, two columns to the left

Topic says it all. I have Sheet 1 with a column of numbers. I have Sheet 2 with 100 columns and 100 rows of numbers. I want to Lookup a value on Sheet 1 in the array on Sheet 2 and return a value from the array on Sheet 2 that is in the same row, but two columns left from the value.
Example
ABCDE
12345
67890
If my value on Sheet 2 is 4, I want to return 2.
I've tried to figure out the Lookup function without success.
=index(A2,'Weekly Summary'!A52:LR106,'Weekly Summary'!A52:LR106)
I've tried fooling around with column() without success.
I keep getting Parse errors, or Out of Range errors. I can't even figure out how the base function works. It never seems to return anything.
Any help would be appreciated!
Sample Sheet:
https://docs.google.com/spreadsheets/d/1607mFQShPpo0Hv--4oYANQvThSszS32yE3KZc_YwqmU/edit?usp=sharing
=ARRAYFORMULA(IFERROR(VLOOKUP(A1:A, {
Array!C1:C,Array!A1:A;
Array!D1:D,Array!B1:B;
Array!E1:E,Array!C1:C}, 2, 0)))

Resources