AverageIF formula error causing error when retrieving data - google-apps-script

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,"-.*",""))

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

apps script vlookup not found?

I rearranged some columns and now my code isn't working. I'm trying to use vlookup to get values from another table.
var name = ss.getRange('G'+lastRow);
name.setValue('=VLOOKUP("Form Responses_Images/"&B'+lastRow+',importrange("https://docs.google.com/spreadsheets/d/###","Form Responses!Q:AA"),8,false)');
SpreadsheetApp.flush();
name.copyTo(name,{contentsOnly:true});
The table that I need to fill in:
The table that I am using to look up info:
Right now when I run the script, the cell just freaks out and gives the error:
Error
Did not find value 'Form Responses_Images/20ba4a5c.Upload.040416.jpg' in VLOOKUP evaluation.
But as you can see both tables have the value Form Responses_Images/20ba4a5c.Upload.040416.jpg in it?
You need to fix the importrange function and the column index. Start from column V and get the 3rd column after that.
Replace:
name.setValue('=VLOOKUP("Form Responses_Images/"&B'+lastRow+',importrange("https://docs.google.com/spreadsheets/d/###","Form Responses!Q:AA"),8,false)');
with:
name.setValue('=VLOOKUP("Form Responses_Images/"&B'+lastRow+',importrange("https://docs.google.com/spreadsheets/d/###","Form Responses!V:AA"),3,false)');

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.

how to retrieve data from a column and produce that value into a new column

I'm super new to R and have a question on how to do something. I listed the things that i got to work so ppl have an idea on what is going on. the thing im having trouble with is in bold.
-I have a data spreadsheet with 2 columns of data (End and CTCF). With the CTCF column having more cells
-I want to to take one value from the "End" column and subtract that value from each individual value in "CTCF" column (so i would have a bunch of products from each calculation)
-I want to then compare those products and find the miniumn absoulute value and the coresponding spot in the CTCF column
-then place that value into a new column ajacent to the corresponding End value.
I wrote a while loop (i know there is probably a WAY easier method) and got the calulation/comparison thing down. I was even able to output the location of the CTCF cell that contains my value of interest see below:
*
*data2<-read.csv("farah.csv")
head(data2)
periph_ctcfs<-list()
temp<-vector(mode="numeric", length = 356)
count<-1
for(i in 1:length(data2$CTCF)) while (count<357)
{
End<-data2$End[count]
periph_ctcfs<-(End-data2$CTCF)
periph_ctcfs<-abs(periph_ctcfs)
periph_ctcfs<-which.min(periph_ctcfs)
print(periph_ctcfs)
temp[]<-data2$CTCF[periph_ctcfs]
count<-count + 1;
}*
The problem is when im trying to produce the new "periph_ctcfs" column, when im trying to insert it into the "temp" vector, the last printed number gets placed within all the cells of the "temp" vector. It feels like that each time the loop goes through its not inserting the retrieved value into "temp". Can anyone help? Thanks ive included a link to a photo (below) so you can get a visual on the layout of the data. Sorry for being a n00b.
For clarity purposes:

Why does my Apps Script reference the wrong row?

The Goal
I am trying to create a spreadsheet using some custom functions. The purpose for the sheet is to keep score in a quizzing competition. The top row has the question number, the second row the score, and the third number the number of fouls for that question.
The Problem
After noticing some problems with the score calculation, I was able to narrow the problem down to the part of the code where I add up the fouls that occurred prior to the current question. It seems that no matter what I do, the code sums over the question row, not the foul row.
Attempted Solutions
The extremely strange thing is that no matter what I change the reference cells to, it always produces the same result (i.e. it still references the question row same as it always has).
Example
I'm not sure if that makes any sense, but I've made an example sheet here so you can see what I'm talking about and try to figure out what is going on. Keep in mind that I'm well aware that I could accomplish what I'm trying to do in the example sheet with a simple built-in formula, but since there's no way to use worksheet formulas on the Apps Script side, I have to create my own version of it. I've made the example editable for anyone with the link, so you should have full access to it; but if you have problems, just let me know, and I'll see what I can do to fix it.
In your For loop, you are summing the indexes rather than the values:
Try:
for (var PrevValue in PrevValues[0]) {
Sum = Sum + Number(PrevValues[0][PrevValue]);
}
EDIT:
You'll also need to account for the case where you pass in a single cell rather than a range (=mySum($B4:B4)), because in that case the value is passed directly instead of an array.
if(PrevValues instanceof Array){
for (var PrevValue in PrevValues[0]) {
Sum = Sum + Number(PrevValues[0][PrevValue]);
}
}else
Sum = PrevValues;