Expanding a difficult formula using ARRAYFORMULA while avoiding circular references (Google Sheets) - arrays

I'm trying to set up a formula in Google Sheets that does this...
=IF(IFERROR(INDEX(Matches!$L$2:$L,MATCH($A2&(B$1-14),Matches!$H$2:$H&Matches!$M$2:$M,0)))=1,
IFERROR(OFFSET($A$1,INDEX(Matches!$I$2:$I,MATCH($A2&(B$1-14),Matches!$H$2:$H&Matches!$M$2:$M,0)),COLUMN()-1)-(1/(2*($A2)^2))),
$A2)
That is to say, IF(match was won, take the current period's rank of your defeated opponent and do math to it, else show last period's rank).
But I want to set it into an ARRAYFORMULA so that it will expand automatically. What I have is this (and it doesn't work):
=ARRAYFORMULA(IF(IFERROR(VLOOKUP($A$2:$A&($B$1:$1-14),{Matches!$H$2:$H&Matches!$M$2:$M,Matches!$L$2:$L},2,0))=1,
OFFSET($A$1,VLOOKUP($A$2:$A&($B$1:$1-14),{Matches!$H$2:$H&Matches!$M$2:$M,Matches!$I$2:$I},2,0),SEQUENCE(1,COUNTA($B$1:$1),2,1))-(1/(2*($A$2:$A)^2)),
$A$2:$A))
What it should look like is this:
https://i.stack.imgur.com/Ui3nE.png
How it actually comes out is:
https://i.stack.imgur.com/tQOl7.png
All of those errors are the same message, which is that VLOOKUP couldn't find 143997, which is just the first value pair. I've tried using VLOOKUP/MATCH, but it produces a circular reference error.
Is this possible? I'm willing to believe it's not, but I thought I should ask. Thanks for any help you can offer.

You can't use that OFFSET formula within ARRAYFORMULA. When the VLOOKUP throws an error the OFFSET is not able to handle it. That's why it won't work. You should apply your math on the output of the VLOOKUP.

Related

Google Sheets Arrayformula Calculating Very Slow

I made a Google Sheet to track some metrics at my job. In a simple explanation, I create annotations (or tracks) on images and submit it for review. If it is reviewed and sent back to me, I fix it and add whatever I missed and send it back.
In order to track my progress, I wanted to create a formula that tracks how many total tracks I missed for each task (most recent attempt - earliest attempt). It took some finagling, but I finally got a formula that works. My only complaint is that it works extremely slow. Here is my formula:
=ARRAYFORMULA({"Number of Tracks Missed"; IF(NOT(ISBLANK($F$2:$F)), IF($G$2:$G = 1, 0, (VLOOKUP($F$2:$F,SORT($B$2:$C, $A$2:$A, FALSE), 2, FALSE)) - (VLOOKUP($F$2:$F, $B$2:$C, 2, FALSE))), "")})
Column G is a count of how many times I have worked on a task, so if I've only had it once, then I didn't miss anything so that equates to 0. If it's been more than once, I use a complicated VLOOKUP combined with a SORT that flips the list of my tasks to the reverse order, so the VLOOKUP will find the most recent attempt, then subtract my earliest attempt from it.
Like I said, this formula works and gives the correct response every time, it's just super slow. Is there a way I can speed this calculation up, or is this the best/only option I have? I'm somewhat new to using formulas like this, so any help is appreciated.
EDIT:
Thanks to player0 for pointing me in the right direction. My formula was fine, the problem was all the extra rows I had in the sheet. For some reason, There were 32,000+ rows. With the Arrayformula calculating for every single one, even if it's just with blanks, it was taking a long time.
As soon as I deleted the extras, it now calculates almost immediately.
somewhere along the path of creation of your sheet an error occurred and added 32k of empty rows to the sheet which caused you that decreased response.
if you don't need so many rows - delete them. your formula is fine.

Excel calculate smallest of X columns within Y columns, ignoring zeros

I'm trying to calculate the sum of best segments in a run. For example, each Km gives a list as such:
5:40 6:00 5:45 5:55 6:21 6 :30
I'm trying to gather the best segments of 2km/3km/4km etc and would like a simple code to do it. At the moment, I'm using the formula
=Min(If(B1=0,9:9:9,sum(A1:B1),If(C1=0,9:9:9,sum(B1:C1))
but this goes all the way to 50km, meaning a very long formulae that I then have to repeat slightly differently at 3km, then 4km, then 5km etc. Surely there must me a way of
generating an array of summed columns of every n column, then iterating over that to find the min while ignoring values of 0?
I can do it manually for now, but what if I want to go over 50km? I might want to incorporate bike rides/car drives in the future just for some data analysis so I figured it best finding an ideal formulae now.
It's frustrating as I could code it and I want to avoid VBA ideally and stick to formulae in Excel.
Here is a draft of the case where there aren't any zeroes just for groups of 2Km. I decided the simplest approach initially was to add a couple of helper rows containing the running total of times (and for later use counts) and use a formula like this to subtract them in pairs:
=MIN(INDEX(A2:J2,SEQUENCE(1,9,2))-IF(SEQUENCE(1,9,0)=0,0,INDEX(A2:J2,SEQUENCE(1,9,0))))
but if you have access to recent additions to Excel 365 like Scan you can do it without helper rows.
Here is a more realistic scenario with a couple of zeroes thrown in
=LET(runningSum,Y$4:AP$4,runningCount,Y$5:AP$5,cols,COLUMNS(runningSum),leg,X7,
seqEnd,SEQUENCE(1,cols-leg+1,leg),seqStart,SEQUENCE(1,cols-leg+1,0),
times,INDEX(runningSum,seqEnd)-IF(seqStart=0,0,INDEX(runningSum,seqStart)),
counts,INDEX(runningCount,seqEnd)-IF(seqStart=0,0,INDEX(runningCount,seqStart)),
MIN(IF(counts=leg,times)))
Note that there are no runs of more than seven consecutive legs that don't contain a zero so 8, 9, 10 etc. just work out to 0.
As mentioned you could dispense with the helper rows by using Scan, but not everyone has access to this so I will add it separately:
=LET(data,Y$3:AP$3,runningSum,SCAN(0,data,LAMBDA(a,b,a+b)),
runningCount,SCAN(0,data,LAMBDA(a,b,a+(b>0))),leg,X7,cols,COLUMNS(data),
seqEnd,SEQUENCE(1,cols-leg+1,leg),seqStart,SEQUENCE(1,cols-leg+1,0),
times,INDEX(runningSum,seqEnd)-IF(seqStart=0,0,INDEX(runningSum,seqStart)),
counts,INDEX(runningCount,seqEnd)-IF(seqStart=0,0,INDEX(runningCount,seqStart)),
MIN(IF(counts=leg,times)))
Tom that worked! I learnt a few things on the way too and using the indexing method alongside sequence and columns is something I had not thought of. I'd never heard of the LET command before and I can already see that this is going to really help with some of the bigger calculations in the future.
Thank you so much, I'd like to show you how it now looks. Row 3087 is my old formula, row 3088 is a copy of the same data using the new formula, as you can see I've gotten exactly the same results so it's clear that it works perfectly and it is can be easily duplicated.

Multiple IF QUARTILEs returning wrong values

I am using a nested IF statement within a Quartile wrapper, and it only kind of works, for the most part because it's returning values that are slightly off from what I would have expected if I calculate the range of values manually.
I've looked around but most of the posts and research is about designing the fomrula, I haven't come across anything compelling in terms of this odd behaviour I'm observing.
My formula (ctrl+shift enter as it's an array): =QUARTILE(IF(((F2:$F$10=$W$4)($Q$2:$Q$10=$W$3))($E$2:$E$10=W$2),IF($O$2:$O$10<>"",$O$2:$O$10)),1)
The full dataset:
0.868997877*
0.99480118
0.867040346*
0.914032128*
0.988150438
0.981207615*
0.986629288
0.984750004*
0.988983643*
*The formula has 3 AND conditions that need to be met and should return range:
0.868997877
0.867040346
0.914032128
0.981207615
0.984750004
0.988983643
At which 25% is calculated based on the range.
If I take the output from the formula, 25%-ile (QUARTILE,1) is 0.8803, but if I calculate it manually based on the data points right above, it comes out to 0.8685 and I can't see why.
I feel it's because the IF statements identifies slight off range but the values that meet the IF statements are different rows or something.
If you look at the table here you can see that there is more than one way of estimating quartile (or other percentile) from a sample and Excel has two. The one you are doing by hand must be like Quartile.exc and the one you are using in the formula is like Quartile.inc
Basically both formulas work out the rank of the quartile value. If it isn't an integer it interpolates (e.g. if it was 1.5, that means the quartile lies half way between the first and second numbers in ascending order). You might think that there wouldn't be much difference, but for small samples there is a massive difference:
Quartile.exc Rank=(N+1)/4
Quartile.inc Rank=(N+3)/4
Here's how it would look with your data

Excel Index Match Small - Formula working only in manual mode

I'm trying to adapt a formula for my needs, but I can seem to make it work only in Manual calculation mode for some reason. If Automatic mode is selected formula returns 0 on every row.
In essense formula is returning ALL matches based on the Blue keyword in column I matched in the sheet DIL-2018-08-14, column H. It all works great ONLY in manual mode and only after manual recalculation on every cell.
Can someone advise if there is was to avoid this and make it wortk in automatic mode as well.
The formula is:
=IFERROR(INDEX('DIL-2018-08-14'!$H$9:$H$502,SMALL(IF(ISNUMBER(SEARCH(LEFT(I8,FIND(" ",I8)-1),'DIL-2018-08-14'!$H$9:$H$502)),ROW('DIL-2018-08-14'!$H$9:$H$502)-ROW('DIL-2018-08-14'!$H$9)+1),COUNTIF($J$7:J8,"*"&LEFT(I8,FIND(" ",I8)-1)&"*")+1)),"")
Here are the steps to fix it on your own:
Change the whole formula to something with hardcoded values like this:
=IFERROR(INDEX('DIL-2018-08-14'!$H$9:$H$502,1,1),"")
Check whether it works.
Start rebuilding the formula until it fails, building a step by step solution with less hard coded values.
See where it fails.
Think of a solution.
I finaly nailed it! This is the working formula in case anyone needs it. I replaced the COUNTIF with SUM of the occurances of the blue keywords in the static column I, which is reseting the counter for every new keyword.
=IFERROR(INDEX(DIL!$H$9:$H$503,SMALL(IF(ISNUMBER(SEARCH(LEFT(I8,FIND(" ",I8)-1),DIL!$H$9:$H$503)),ROW(DIL!$H$9:$H$503)-ROW(DIL!$H$9)+1),SUM(--(ISNUMBER(SEARCH(LEFT(I8,FIND(" ",I8)-1),$I$6:I8)))))),"")

Solr Distance Filter from a Radius Field

Hi I am very new to Solr queries (like a few hours), so please excuse me if this is a naive question, but is there a way on the geo filter to set the radius from a field.
{!geofilt pt=35.3459327,-97.4705935 sfield=locs_field_location$latlon d=fs_radius}
Or do a subquery to return the value of that field fs_field_job_search_radius and place it in there. I can return the value from the field list so I was hoping it could go in there, in some method.
This is similar to this Filtering by distance vs. field value in Solr but I do not know if he got it working or where I would need to start to write a function as was suggested. Also this is on a Solr server I do not control. It is controlled by my hosting company, so I do not know if I can even create functions. Thanks.
Took a work around, but I got what I was trying to accomplish I believe.
fq={!frange l=0 h=12742}sub(radius_field,geodist(field,point))
The 12742 is the diameter of the earth in km as I still needed a hard number for that, but I doubt most are searching in space. So basically we subtract the distance from radius_field to find out if it is in range.
radius_field - distance
If the results are a positive number than it is within range. If it is a negative number than it is not. Please let me know if I screwed up my logic. Thanks.

Resources