How to Fix 'Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 613. Actual: 1.' error message in google sheets - google-query-language

I'm attempting to write a formula that will sort a sheet of data based of three criteria.
This is for social services, running on google sheets. I have tried to run array_literal's in order to run queries on the array. Furthermore I have tried to mix filter and queries inside an Array formula. I always come back to either a Syntax error, or I find myself needing to create new tables and sort them individually.
=array_constrain(query(arrayformula(query({filter('Troubled Families '!A1:AU, 'Troubled Families '!AA1:AA = 'Troubled Families '!AU1:AU),"select * where F = '"&'Troubled Families '!F14&"'"})),"select * where G = '"&'Troubled Families '!G12&"'"),1,1)
I expect this code to pull out all of the 'Cases' where there has not been an FGC, the case has closed and the number of qualifiers meets the number of eligibility criteria met. However I am only receiving errors.

Related

Query to count cells changes cell's range randomly, by itself

I refer to my previous question.
The problem happens when I use the non-array solution proposed by #Martín (the one that overloaded less my system).
=QUERY(Sheet1!A2:B;"Select A,COUNT(A) where A is not null group by A pivot B")
By itself the Query() works perfectly, but only with non-dynamic ranges. The function, put in "Sheet2", draws the data to be counted from "Sheet1". The range in which the function is applied is a portion of "Sheet1", that's why I entered "Sheet1!A2:B".
In "Sheet1", new cells are constantly added and the sheet automatically organizes the answers into different categories (first_department, second_department, ...). To do this, it adds blank rows between groups of cells (different categories), removes rows in the wrong category to move them in the correct one, removes all blank rows at the end (useless part of the sheet).
At this point, the Query() in "Sheet2" has some error which leads it to consider a range outside the one originally set (it's always the number of cells on the sheet + 1), raising a "#VALUE!".
Function before:
=QUERY(Sheet1!A2:B;"Select A,COUNT(A) where A is not null group by A pivot B")
Function after (an example):
=QUERY(Sheet1!A23:B;"Select A,COUNT(A) where A is not null group by A pivot B")
In this case there were 22 cells in "Sheet1", and the Query() went to "A:23".
I've tried myself to solve the issue in the past week, trying to simulate the situation that led to the problem. I've updated the organization of "Sheet1" by adding new data or deleting some: I haven't been able to find out the source of the error. When I checked the query's behaviour, the range rightly locked at "A2:B", it didn't end up at "A23:B".
I tried deleting the entire sheet and creating a new one from scratch (maybe it was a local bug), I tried changing Google Sheet's country of use (maybe it was punctuation), but that didn't fix anything. I've looked at the Query() and it's, indeed for me, correct under all shapes.
Is there a way to lock the range, so that it doesn't change randomly?
I'd appreciate any effort!
Yes, it's a common issue, you can use INDIRECT to lock the range:
=QUERY(INDIRECT("Sheet1!A2:B");"Select A,COUNT(A) where A is not null group by A pivot B")

AverageIF formula error causing error when retrieving data

I am trying to do an =AVERGEIF statement to retrieve the average of three pointers specific players made. I am getting a "Evaluation of function AVERAGEIF caused a divide by zero error".
The issue is located in "AIO REB & POINTS" sheet and the column for the threes made is 'NBA Players'!$BS3:$BS.
This is the formula I am using
=AVERAGEIF('NBA Players'!$B:$BT,$B3,'NBA Players'!$BS3:$BS)
It's the only stat from my sheet I can't get the averageif statement to work and I have no idea why. I made sure the formate was set to number as well.
copy of sheet https://docs.google.com/spreadsheets/d/1RyxFzdmXu0upWHKAkbICVUUTVf_67KdEYhCy53XlD_s/edit?usp=sharing
In BS column those aren't actually numbers. If you add Value before the Regex in BS, AverageIf works!
=value(REGEXREPLACE(F4,"-.*",""))

Exception: The data validation rule has more items than the limit of 500. Use the "List from a range" criteria instead

I have a google sheet for Competitor backlink Audit. In previous, it was work perfectly. Last day I tried to use my sheet again and this time, it's not worked. It shows the message
Exception: The data validation rule has more items than the limit of
500.Use the "List from a range" criteria instead.
This sheet is working 4 step way.
merging various data using an app script, and it worked perfectly.
filtered merging data using various filter data.
create a data validation, and this step is not worked.
dependent on the 3rd step. So this also not worked.
I tried to fix this, but I can't figure it out.
Here is my sheet URL:
https://docs.google.com/spreadsheets/d/1T2Jsni659wK3m9ZDka875d8wIoNrxYYn55SaKsjPGrc/edit#gid=1602455067
Also, the Code is too long to share
1st URL is the main code set: https://pastebin.pl/view/4f445433
2nd URL is the helper of 1st code: https://pastebin.pl/view/99ccc65e
custom menu here
As the error message says:
You are trying to add too many options to the Dropdown.
If there are more than 500 rows in the sheet which your script tries to use as data validation options - the script will error.
Solution:
Do not use more than 500 options.
You have more values than this - try to break them down into a nested Dropdown e.g. into Main Categories and Sub categories.
Since you do not provide your script or public access to your spreadsheet, I can not give you more details, but make sure that your script does not try to assign more than 500 values for data validation.

The coordinates of the range are outside the dimensions of the sheet (google-script)

I have a really very odd problem, which seems to have to do with the sequence i execute scripts. After investigating for hours, I cant explain it at all.
I have a google sheets script which gets emails from an email account and parses them according to given rules into a speadsheets.
I have many of those methods, all leveraging common classes like getEmails, etc.
Every single method of parsing works well and delivers the respected result. But when I run them in a big method one after the other it reports the error
"The coordinates of the range are outside the dimensions of the sheet."
after executing some of the methods correctly. The error occurs in the following line:
var resultArray = sheet.getRange(startrow, column, sheet.getLastRow(), 1).getValues();
and is based on the call
sheet.getLastRow()
(I can not even call this in the logger, it works for lets say 5 out of the 10 methods and then all the sudden i get the error)
Every of those methods parse a different email with a different pattern but does this only for new emails. Therefore I have to get the hashs of the old emails (thats the call) from the google sheets column 1 to work only on new email hashes. This process breaks somehow.
What is striking me is that i can execute any of the methods isolated without an error.
Any ideas?
As mentioned I have tried isolated and i have tried to change order or to run only 2 of the methods.. with the same result. I assume some variable is not set back properly... but i have no idea how that can lead to this error.
By the way: the code was working for the past few weeks without error (also for the combined method). The errors have started like a week ago without any code changes.
I came across the same issue.
This is a sample of the code that was causing the bug for me:
var priceSheet = ss.getSheetByName(priceSheetName);
var rangeToSort = priceSheet.getRange(2,1,priceSheet.getLastRow(),priceSheet.getLastColumn());
rangeToSort.sort(1);
ss.getSheetByName("my sheet").getRange(startingRow,pasteColumn,pasteHoldings.length,1).setValues(pasteHoldings);
The error The coordinates of the range are outside the dimensions of the sheet was raised on line 4 (similar to your scenario), but the issue was occurring when I was trying to sort a range that extended beyond the last row of the sheet i.e.
last row with contents = last row of the sheet
Sort row start range = 2
Number of rows = priceSheet.getLastRow() <-- this is impossible because the sort row start range is great than 1
The fix for me was to adjust the sort range down by the start row - 1
var priceSheet = ss.getSheetByName(priceSheetName);
var rangeToSort = priceSheet.getRange(2,1,priceSheet.getLastRow()-1,priceSheet.getLastColumn());
rangeToSort.sort(1);
ss.getSheetByName("my sheet").getRange(startingRow,pasteColumn,pasteHoldings.length,1).setValues(pasteHoldings);
This appears to be a bug in Google Sheets script: either the sort functionality, or at the very least the error handling is raising the error with reference to the wrong row.
My recommendation would be to check your use of .getLastRow() and see if it corresponds to a starting row greater than 1. Then adjust the .getLastRow() by starting row - 1
Would you happen to have your sort range starting on something other than row 1?
I was testing this out and I have my data to sort on A7:N100.
What I found was that the max row that I can have is the last row in the range minus the header rows that are not in the range. For example, I have the first 6 rows that aren't in the range. I have my last row in row 100. So my range is only working with A7:N94.
To solve, I ended up adding 6 blank rows to the bottom of my page and set sort range to what I wanted (A7:N100) and this worked.

Replace INDIRECT() in data validation rule

I had a working Excel spreadsheet that used indirect() in the data validation and it worked fine. I uploaded it to sheets and converted it, now the indirect does not work.
I have found a link on the support forum that explains it does not work in Chrome but appears to work in Firefox, and the answers and workarounds seem to be for generating a secondary list... which is what I want, but in a data validation across a row.
I have knocked up a simple test sheet, hopefully public and the script editor is visible:
https://docs.google.com/spreadsheets/d/1KUgrdXKIKlk1DWvDOX9cY3B2VnRH_5h_vKuZJlqUlN8/edit?usp=sharing
Hopefully you can see what I'm after. I want the validation in C8 to be the list of items in the category based in B8; C9 based on B9 etc.
EDIT and Update
The question is about a replacement to indirect() in a data validation rule. While I did find a way round this by using indirect(), I preferred the version mentioned by Desire (to whom I have attributed the answer), but I thought I'd document my solution in case the sheet above becomes unavailable, or you cannot access it, or you just wanted a bit more detail.
So, for My Demo I have this:
In A1:C5 are my lists of data with the titles.
In the range B8:B12 I applied a data validation rule of value in range of A1:C1 - this gives the first dropdown.
In Cell E8 I put the formula =transpose(filter($A$2:$C$5, $A$1:$C$1 = B8)) and then copied this down to E12
Finally I put the following in a function and ran it in the script editor.
function runMeOnce() {
var dst = SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('C8:C12');
var rules = [];
for (var i = 8; i < 13; i++) {
var src = SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange("E" + i + ":H" + i);
var rule = SpreadsheetApp.newDataValidation().requireValueInRange(src).build();
rules.push(rule);
}
dst.setDataValidations(rules);
}
That's all there is, no more onEdit() triggering.
NOTE There is one downside I bumped into with this method though. I have this in place for 6000+ rows in my actual spreadsheet, and across multiple sheets, with some dropdowns having 50-100 items in. This solution seriously eats into the (current) 2 million cell limit.
Hope this helps someone.
Data Validation rule of the type "List of items" takes only a comma-separated list of values as its parameter, and does not evaluate any formulas you try to put there. It does not matter what the function returns, because it will not be called. If you put, say "=sqrt(A10)" in the field "List of items", that only means that the validation rule will require the string "=sqrt(A10)" to be entered in the cell.
Similarly with "List from a Range". Either what you enter parses as range notation, or it does not. The string "=getValidationRange(B8)" does not parse as range notation, hence the error. The function is never called.
The only type of validation that calls a function is "Custom formula". If you use it, then the validation can be performed as intended: for example,
=match(C8, filter(A2:C5, A1:C1 = B8), 0)
requires the content of C8 to be in the column of the table A2:C5 under the heading that matches the category in B8. However, with a custom formula you do not get a dropdown in a cell.
To get a dynamic dropdown, one can either
Use an auxiliary range
For example, enter filter(A2:C5, A1:C1 = B8) in cell F1, so that the F column is for the categories currently selected. The data validation would be "List from a Range", F1:F. This is a fine workaround for one validation rule, but takes more work when you have multiple ones.
Use a triggered script
Use a script that is triggered on edit and sets data validation rules accordingly; this is discussed in How do you do dynamic / dependent drop downs in Google Sheets? among other places.
Based on the sacrificing a goat issue, I did find a simple(ish) way around the problem that still uses indirect().
Set up the named ranges as previously using the titles in CamelCase. In my example I have CatA, CatB, and CatC - i.e. the white space needs removing.
At the end of a row (or in another sheet) transpose the chosen named range (in cell E8: =transpose(indirect(substitute(B8, " ", ""))) copy this down as far as you need.
At this point it's good to note that because we are unsing builtin functions, the speed is so much better, as can be seen by my example.
Now the painful bit. For each subcategory cell (C8, C9 etc in my example), you need to add the validation independently as a range of E8:ZZ8 (obviously ZZ8 needs reigning in a bit) and E9:ZZ9 etc. It doesn't seem to do referential so if you select all the cell in the column, they all only look at the data you specifically type in the box... I might just not have worked out R1C1 notation here, however. I tried.
This can be scripted on GAS to create the R1C1 validation function and then apply it to the range.