How to do a Loop Until Condition in Google Sheets - google-sheets

In my example I am working on a Google Sheets to help me calculate how much staff I'll need for a Call Center at particular times.
My equation for the cells highlighted in blue is =1-(B40/30). The numbers next to it (on the row for 8:30) were an experiment I did in which I say =1-(B40/60), =1-(B40/90) and so forth etc. The idea is that eventually it will equal 90% (0.90) or higher at some point. I need a way to loop and add 30 everytime like I did manually in my example and count how many times I had to do that until I reached the number 90% (or whatever number I put for the highlighted green area in the picture). For example it took 5 steps to get to 90%, so this function should return 5.
How do I do this? I have tried looking into array formulas but can't seem to figure out if this is the right method or not.

Ok, then... Look at the image:
And the code:
=SUM(ArrayFormula(IF($C$4*TRANSPOSE(ROW($A$1:$A)*$C$3)/B9<$C$5,1,0)))+1
All variables are in C1:C5
Final formula is a bit complicated, so at the link below you will find step by step approach to this result (as a single formula)
Link to working copy
I hope it will help you
Edit:
If you want to simplify (based on your comment), look at this:
Code:
=SUM(ArrayFormula(IF($C$4*TRANSPOSE(ROW($A$1:$A))<B7,1,0)))+1

Related

ARRAYFORMULA does not increase cell as it expands

I'm trying to get an ARRAYFORMULA to subtract the current cell from the previous one,
but it appears that if I write
=ARRAYFORMULA((A3:A)-(A2))
The formula does not increase of one cell as it expands.
here's an example of what I get
https://docs.google.com/spreadsheets/d/1ci4kiNCgjBZK0Ue218IRIk5t8tSmElF5EgbIxb1_Q9w/edit?usp=sharing
it's clear that it keeps referencing A2 (but I'm not using $A$2 in the formula)
if I wouldn't use ARRAYFORMULA I would simply use
=SUM(A3-A2)
Can anyone suggest me a solution?
Your sample spreadsheet is still "View only"; so neither I nor anyone else can directly leave our solutions. However, place the following formula in D1:
=ArrayFormula({"Difference"; IF(A2:A="",,IFERROR(A2:A-OFFSET(A2:A,-1,0)))})
This will create the header (which you can change within the formula itself as you like) and all results.
(Adjusting to the location in your actual spreadsheet, as indicated in your post, this would be =ArrayFormula({"Difference";IF(L7:L="",,IFERROR(L7:L-OFFSET(L7:L,-1,0)))}).)
Couple Comments
You should accept Erik Tyler's answer as he put in more work and helped you present your problem more clearly. However these formulas allow for some more flexibility if you want any values below the rows (which now that I think about it doesn't make a lot of sense based on having a dynamic array flowing down, but conceptually maybe someone will find it useful).
Simple Formula will require one cell below your range to be blank:
=iferror(filter(filter(N(A2:A),A2:A<>"")-N(A1:A),A1:A<>""),"")
Complex Formula will allow values directly below (which I again admit seems nonsensical considering the whole point of this is a dynamic expansion down rows...)
=Filter(filter(filter(N(A2:A),A2:A<>"")-N(A1:A),A1:A<>""),ISNUMBER(filter(filter(N(A2:A),A2:A<>"")-N(A1:A),A1:A<>"")))
I gave a demo on your page.

Find a way to increment formula in merged cells and blank cells

It's my first time posting here, I tried to look for something similar to what i am looking for but couldn't find anything, but if I just didn't look enough, I apologize.
My problem is as follows:
https://docs.google.com/spreadsheets/d/10yx-WO_SlOnFLNW83N8wucOrcexfLtt1TE2FDzTAQbc/edit#gid=799857548
I have a data table with information I receive from somebody. I then need to use that information to feel kind of individual product data table on another sheets, and add more to it.
Instead of copy everything of sheets one in sheets 2, I would like it to feel by itself.
I tried with =Cellsadress or =OFFSET and other stuff but couldn't manage to get what I want.
When i put every formula in the green table on sheets 2 and try to increment it by dragging down, the formula values increase by 25 approximately. but i want it to increase by only one, or find another way to show the information in the column of sheets 1 to reflect in different cell of sheets 2.
In my real document i have 100 of lines, so i cant do it manually like i could do with 4 lines.
Is there a way to do that?
If somebody have a solutions i would be gratefull
try this formula for C32 =INDIRECT("'Sheets 1'!F"&(int(row()/25)+2))
when you copy-paste this formula into cell C57 or C82, it will take values from 'Sheets 1'!F4 and 'Sheets 1'!F5, respectively

Google Sheets Formula Sometimes does not work with Merged Cells

So I have created an invoice spreadsheet in Google Sheets and have used merged cells extensively in order to create a cleaner look for the invoice.
Here is the problem that I am having: sometimes, my simple subtraction formula does not give me a correct result. The formula is supposed to subtract the Unsold balance (cell V27) from the Beginning Balance (cell R27).
Again, there is nothing wrong with the formula itself, as it works correctly 99% of the time, but every now and then, it just gives me an answer matching the Beginning Balance.
Also here is a link to a copy of the spreadsheet for anyone willing to take a look. https://docs.google.com/spreadsheets/d/1bf_QE-u36mo4AKyqg7Dk11gwoR0p5g0qveIazR83Xbk/edit?usp=sharing
Has anyone else ever had this situation happen to them? What could possibly be causing it, and more importantly, how can it be fixed to be more reliable?
Those of us who work professionally developing Sheets solutions have a few basic rules that we follow and encourage others not to break. Among them is "Never merge cells anywhere that calculations or comparisons will be (or ever might be) performed or assessed."
While what you're seeing might seem to be a glitch, I wouldn't call it that. Merged cells don't really get rid of the cells you don't see. For instance, your cell R27 doesn't "get rid of" cells S27, T27 and U27. It just holds them in memory, presumably empty. But remember that, inside Sheets' "memory," it doesn't "see" a grid. It's just 1's and 0's. When a grid is new and no cells are merged, Sheets "finds" each cell (using the best analogy I can give) counting over and down by 1's and 0's that are very small and tightly packed. Hold that thought...
Also note that many people are surprised when they have multiple complex calculations going on and get a returned answer that is off from what they expect in a cell further down the calculation chain. This is because Sheets uses floating decimal points. For instance, "one divided by three" is about 0.333. But in reality, that extends very far out: 0.33333333333333333333. But that can't go on forever or Sheets wouldn't be able to run. So at some point it gets truncated. Eventually, those extra decimal-extras will start to add up and bump numbers up (or down) by small degrees. All of this is handled by the same 1's and 0's that run everything else.
Back to merged cells. Finding and accurately "reading" merged cells gets less accurate the more of them you merge, because the process is relative to other cell locations in memory. After a while, the "floating decimal point" nature of Sheets starts to lose track, especially (I've observed) if you've got merged cells using the same sort of relative formula reference that you're using (e.g., a lot of your stacked merged cells are referencing yet another merged cell: BB2. So (again by analogy), Sheets is trying to "guess where it is by using clues." Perhaps it found something correctly in merged cells Z-AA-AB-AC23 that referenced merged cells BB2-BB3-BC2-BC3; but that time, you asked it to add merged cells R-S-T-U23 and V-W-X-Y23 and subtract merged cells V-W-X-Y24 ... where in the following set of merged cells, Z-AA-AB-AC24, you still asked for the BB2-BB3-BC2-BC3 reference but not the V-W-X-Y24 subtraction. And so on...
To add to this, you've got row heights changed all over the place. Some are set to specific heights, while others are fit to data.
You get the picture.
If Sheets is trying to find things by moving over and down from cell A1, but there is no regularity, sometimes, it just throws it's hands up and says, "Where the h-double-hockey-sticks am I anymore?" When you then reload the sheet or delete and replace the formula, it starts out at A1 again and plays Chutes and Ladders on the broken board and might shift one "floating" teeny-weeny 1 or 0 a different way from last time... and find what you wanted it to find again.
You also-also wind up with a sheet that is 56 columns across, when you probably only needed it to be 12 or 15. Likewise, you've extended the number of rows beyond what it needed to be. So you're slowing down your processing by a lot.
THE SHORT VERSION:
As nice as merged cells might look, they are a computing nightmare. I've been working with spreadsheets since they were invented, and I've literally never had a need for merged cells (though I've occasionally used them in areas that are purely aesthetic).
THE SOLUTIONS:
1.) Remake the sheet without merged cells.
-or-
2.) Try encompassing all of the merged-but-hidden cells in your calculations. This at least gives Sheets a wider net to cast. For instance, in your example above, you reference this formula:
=IF($BB$2<>"Rental","",R27-V27)
Try (where possible) to include the whole range you merged:
=IF($BB$2<>"Rental", "", SUM(R27:U27) - SUM(V27:Y27) )
Technically, you could also include all cells in the BB2-BB3-BC2-BC3 merge:
=IF(AND($BB$2<>"Rental", $BB$3<>"Rental", $BC$2<>"Rental", $BC$3<>"Rental"), "", SUM(R27:U27) - SUM(V27:Y27) )
However, try the shorter route with just the SUMmed merged ranges and see if it holds up. If so, stick with that. If not, go with referencing every cell in ranges you merged.
You've clearly put a lot of work into setting up this sheet. So I'm sure this isn't the easy answer you were hoping to hear. But I hope it does give you some direction for next steps.
For me, the simplest solution is to lock-reference the uppermost cell of the merged cells.
Instead of referencing in the top formula as B2, reference as $B$2. This way, your formulas in other cells will reference the same value as required.
USE LOCK-REFERENCING:
$B$2

Google sheets filter custom formula is moved by one row

I created a column of total profit in google sheets and my goal is to filter values which are less then 70% of previous profit value (screenshot so you can understand).
But when I apply this condition to the filter custom formula (here) is not filtering the values which are less then 70% but the values before them, instead it is moved by one row (hopefully you will understand).
It may be it is something easy to fix but i really couldn't find out. Thanks for your future advice and time!
*EDIT: https://docs.google.com/spreadsheets/d/1JcHVrpOCLEdMiTF3YD0qvJiHPsi6J2QwFPN-XOfAipY/edit?usp=sharing sheet in view mode
try to shift it:
=$B2/$B1>0.7

How to average the last seven values in a column?

I am trying to find the average of the seven most recent entries in a row, as seen in
this
spreadsheet.
I found a few questions similar to mine, but I am still pretty confused on how the answers work. The questions similar to mine can be found on the left side of my spreadsheet.
I think that the formulas would work for me with a few simple adjustments of which values to use, but I can't seem to figure it out. I would really appreciate if someone could explain one of the existing answers or come up with another one that works.
The spreadsheet is updated daily, so I need something that would continue to work as more and more data is added to the column.
Try:
=round(AVERAGE(OFFSET(H1,MAX(ARRAYFORMULA(ROW(H:H)*--(H:H<>"")))-7,,7)))
here's working sample
Explanation
We are getting the last non empty row: MAX(ARRAYFORMULA(ROW(H:H)*--(H:H<>"")))
Then with offset formula we are getting the range of last 7 cells in a column.
And then just use AVERAGE.
More info
You may find more info about finding the last non empty row here:
Selecting the last value of a column
Another way is to use INDEX and MATCH. The first match finds the position of the last number in the range and takes 6 away from it: the second match finds the position of the last number in the range. Passing it through the INDEX function gives a reference that you can use to give a range of 7 cells for AVERAGE to work on.
=average(index(H:H,match(999,H:H)-6):index(H:H,match(999,H:H)))
So my answer is like your Link2
The big snag here is if you have a text cell in the range (like "Nothing") it is much more difficult to work out which cell to start from to get an average of 7 cells. I think I know how to do it in Excel using OFFSET but offset doesn't seem to work in the same way in Google Sheets.
However I can see there is a solution to this in your Link3 which should work for you if you change A:A to H:H and SUM to AVERAGE. I have tested it on the average of the last ten cells which includes a "Nothing" cell:
=ArrayFormula(AVERAGE(QUERY(SORT(H:H,ROW(H:H)*ISNUMBER(H:H),0),"select * limit 10")))
and it gives the correct answer 61.8.
The way array formulas work in general is that instead of passing a single value to a function you pass a whole range or array (a list of values) and the function processes them one by one. The above formula takes the whole column H:H and sorts it on the row numbers in descending order but those cells which don't contain a number give zero in the multiplication and are sorted to the bottom. Then the query takes the top (in my case) 10 cells and passes them to AVERAGE.
BTW this doesn't have to be declared as an array formula: this also works
=AVERAGE(QUERY(SORT(H:H,ROW(H:H)*ISNUMBER(H:H),0),"select * limit 10"))

Resources