Google Sheets Formula Sometimes does not work with Merged Cells - google-sheets

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

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

Not calculating correct number or refreshing

I am using Google Sheets and have just noticed a very worrying issue.
I have a situation where I have a number (for example 4.99) in the left column and the right column through a series of formulae may come out as 30% or so. I changed the number in the left to 5 and the number is the right column jumped to 50% or so (highly unexpected to see such a large jump for such a small increase, so I decided to investigate). When I typed 4.99 back into the left box, the result in the right was just slightly lower than the 50% or so.
I then checked several other numbers in the left column. It turns out that this was the same for all of them. I.e. the number in the right column was not calculating properly until I changed the number in the left column and pressed enter. How is this possible? I have never had this problem with Excel and I don't know what to do other than to migrate back to Excel as I am now doubting the reliability of all the spreadsheets I have on Google Sheets.
Has anybody else come across this problem?
I managed to figure it out moments after posting this.
In the column for some reason some of the cells were considered numbers and some text. I performed an if statement (<10), which came out FALSE for all cells considered text.
Quite dangerous - surely the cell on the right should show an error and not assume FALSE?

Comparing each value in a column to the value in the column next to it

I'm creating an expenses spreadsheet, and I want to be able to compare what each person has paid on each item, to what is owed. If it's < what's owed, it will be red, if =>, green. I know I can manually conditionally format each cell to do this, but I'm looking for a solution I can use to simplify the sheet for month-to-month editing, with potential to add new expenses or remove them without having to later manually conditionally format the new expense.
I've looked into a few others with similar questions and tried some custom formats. First I went with the simple "if less than column [whichever it is next to] set color to red" and no luck, and one suggested a formula like this: =($H2>=$G2)*($H2<>"") though honestly I can't say I fully understand it. I have a grasp on it to a certain extent due to my coding background, but not quite enough. I feel this would be way easier if I was coding and could just use a for each statement...
I expected the cells (specifically for the greater than function) to be green, but actually it's counting all cells as less than the ones next to them, regardless of the values.
Imgur images
your issue is that the conditional formatting is offset by 1 row because you trying to apply it on range H1:H13 but formulas you use works with range H2:H & G2:G. therefore do it like this where you start from H2:

How to do a Loop Until Condition in 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

Resources