Files
hpr-knowledge-base/hpr_transcripts/hpr1495.txt

183 lines
16 KiB
Plaintext
Raw Normal View History

Episode: 1495
Title: HPR1495: 27 - LibreOffice Calc - Calculations and the Formula Bar
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1495/hpr1495.mp3
Transcribed: 2025-10-18 04:13:07
---
our
Hello, this is Ahuka and welcome to Hacker Public Radio and another exciting episode in
our ongoing series of Libra Office and we are now moving into and have for the last couple
of episodes Libra Office Kelk, the spreadsheet program.
We're going to continue with this. We have looked in general at what spreadsheets are a little bit
of their history. We've looked at the concept of a cell and taken a look at cell addresses and how
all of that works. Now, the idea of a spreadsheet is it is a program for doing calculations. So
I think this is a good time for us to take a look at how we do calculations.
Now, in general, a cell of a spreadsheet can contain any one of three things. The first is a number.
4, 2, 73, 157. These are all numbers. Or it could contain text, dog, cat, milk. All of those
things are text. Or it could contain a formula. And naturally what we want to look at now.
All calculations are done using formulas. And a formula occurs whenever a cell has contents
that begin with an equals sign. And that's the signal to Calc that it needs to perform a calculation.
So for instance, if you went to a cell and you typed A3 plus B3, Calc would examine this.
They would see the letters and the plus sign and decide that the contents of the cell were a
text string. After all, it cannot be a pure number with those other things in there. So what else
could it be? But if you place an equals sign in front so that the contents now reads equals
A3 plus B3, then Calc knows this is a formula and will perform the calculation. It'll take a look at
whatever the contents of A3 are. Add them to the contents of B3 and store the result in the cell
where this formula is. Now one of the best ways to interact with a cell that contains a formula
is to use the formula bar, which normally appears just above the cells of the spreadsheet proper.
And so that is a bar that starts off with what is called a name box. And that would have a
cell address in it typically. And that cell address would be the cell that you are in at the moment.
So you can always tell which cell you're editing. But it can also be used to move to a different cell.
Type in a cell address, press the Enter key, and you will jump to that cell. So that's useful.
That's worth knowing. Next to the name box, there is an icon that looks like a script or italic
letter f and a magic wand. This is the function wizard. Since functions will be worth many tutorials
in themselves, we won't spend any time on this right now. Other than to note, this is where you
access all of the built in mathematical functions that Calc offers. By the way, that script or italic
f is the mathematical symbol for function, hence the icon. The next icon is a Greek uppercase
sigma, which is the mathematical symbol for a sum. One of the things you do often in a spreadsheet
is add up a bunch of numbers. If you had a column of numbers, for instance, column B,
that were in cells B2 through B13 inclusive, you can then go to cell B14 or even lower to B15.
Click on the sum symbol and Calc would guess that what you wanted to do was to add up those
numbers and place the total in this particular cell. Now, you could do this in cell B14 because
that's empty, right? Your numbers are in B2 through B13. I find it convenient very often just for
the sake of appearance to make it easier for people to understand what's going on in a spreadsheet
to skip a line. I think that makes it somewhat easier to read and Calc takes this in stride.
Now, when you do this, the formula bar will now show you what is in this formula and it will read
something like this. Equals sum, all uppercase, parentheses, capital B, number two, colon, capital B,
the number 14. Why 14? Because I, in cell 15, when I clicked the sum button and so it's
including B14 in the formula. Now, I don't really want to do that, so what I would probably do is
just change that and make it read sum B2 colon B13 because who knows? Maybe at some point someone's
going to type something into cell B14 and throw everything off on me. Now, what's the formula telling
us? First, it begins with an equal sign which is telling Calc to perform a calculation.
Second, it contains the formula name of sum. Now, that is the name of one of the built-in formulas
or functions that Calc has. Now, I mentioned before that with the function wizard, we can access a
huge number of functions, but this is one of the ones that is almost always used by people. It's
the most common one and so they pull it out and give it its own place on the formula bar.
And that's a good thing. It's going to save you time in the long run.
Now, all of the numbers, all of the letters I should say that we see here are uppercase.
It doesn't matter. You could type it in all lowercase or you could have some lowercase with the
B's uppercase. It doesn't matter. In fact, what will probably happen is when you're not looking,
Calc will decide to just change everything back to uppercase on you. So, don't worry about that.
Now, next, we note that the expression B2 colon B13 is inside of parentheses.
This is common for all functions, but it's important to understand how we use parentheses in formulas.
This is important because the best way to build formulas is to use parentheses to set off parts of
the formula. This helps to resolve ambiguity. For instance, what is the value of equals 2 plus 3 times 4?
Now, you could rely on understanding the rules for order of operations and decide that multiplication
needs to be done first. In that case, you would first multiply 3 times 4 and that gives you an
answer of 12 and then you can add that 2 plus 12 and that comes out to be 14. But suppose you
actually wanted to do the addition first. So, what you wanted to do was add 2 plus 3, giving you 5
and then multiply that by 4. Well, then the answer is 20. Now, you can rely on a good understanding
of the order of operations, but the more complicated the formula gets, the harder that is to do.
And you really are going to do a lot better if you just get used to using parentheses.
For instance, if you wanted to add the 2 and the 3 first, the way to write the formula would be equal,
open parent, 2 plus 3, close parent, multiplication sign, 4.
And now there's no ambiguity at all. You want to do the calculation inside the parentheses first,
then the remaining calculation when that is complete.
For more complicated expressions, you can do what is called nesting of parentheses.
This means that one calculation set off inside of parentheses is contained within another
expression also inside of parentheses. And the rule is that the innermost set of parentheses
always gets calculated first. Then calculations are done in order as you work outwards.
For example, take the expression equals 2, open parentheses, 3 plus open parentheses,
4 times 5, close parentheses, close parentheses.
Well, this would be resolved by first looking at the innermost set of parentheses, which contains
the expression 4 times 5, which would resolve to 20. Then the next set of parentheses working
outward has us add 3 to the 20 that we got from that earlier calculation, giving us 23.
Then the whole thing is multiplied by 2, giving a final result of 46.
Or so you might think, we all expect that when a number appears in front of a parenthetical
expression that we will multiply it, but calcates ambiguity. So if you actually entered the above
formula, calc would throw an error and ask you if it could change the formula to what it considers
a proper formula, which is equals 2, multiplication, open parent, 3 plus open parent, 4,
multiplication, 5, close parent, close parent. So best practice in Libra Office is to always use
parentheses to make clear the order of operations and always use mathematical operators,
that's the general term for symbols we use, like plus minus the sigma, the square root sign,
etc. And did you know that in addition to the uppercase sigma for sum, there's also an uppercase
pi for product. And why those letters? They are the equivalent sounds for s and p in Greek,
s for sum, p for product. Now with nested parentheses, you do need to be careful that every
parenthetical expression is properly closed, by which we mean that the open parenthesis sign is
matched by a closed parenthesis sign. In the example I gave before, you notice that I had two
open parents as I moved through the expression and at the very end I had two closed parents right
after one after the other. You should get in the habit of always being very careful about closing
your parentheses. Calc will do its best to figure out what it thinks you meant.
So if you wrote equals two, multiplication, open parent, three, plus open parent, four,
multiplication, five, close parent, and you end it right there. You have not closed
the outside parenthesis. However, Calc will probably go ahead and compute that and give you the
answer of 46. You could get a little more complicated. Two, multiplication, open parent, open parent,
three, plus open parent, four, multiplication, five, close parent, plus two.
I'm missing two closed parents now. But if I enter that in the Calc, I will get the answer of 50,
which means that Calc is inferring that those two closed parents should have come after that final two.
And in fact, that's an unnecessary set of parentheses if you do it that way.
Now, the fact that Calc does that and it gives an answer of 50 may make you think you don't have
to be that careful. Believe me, you do have to be careful because the more complicated your formulas
get, easier it is to just make a mistake and get something that doesn't mean anything at all
like what you thought you were doing. Keep in mind, there's a story I remember about a billion
dollar spacecraft that crashed into Mars because of a really trivial little math error in the calculations.
You don't want to be the person who creates that math error.
Now, the last icon on the formula bar is an equal sign and clicking this will put an equal sign at
the beginning of the formula area for whatever cell you are in. It also changes the icons on this
bar. In fact, the sum icon does as well because it inserts that formula. When you start working on a
formula, and that means you're now starting potentially to edit things, the sum and equals buttons
go away and they are replaced with a red X and a green check mark. These keys are used to either
discard your edits, which is what the red X does, or accept them, which is what the green check mark does.
You need to get used to these two buttons or you will be very frustrated trying to edit formulas.
The red X does not, for instance, clear a cell unless that cell was already cleared before you
started editing. What it really does is to revert the cell to whatever contents it had before you
started editing. Editing a formula begins when you click on the formula area and this is technically
called the input line and then you place your insertion mark there. If the cell you are editing
already contains a formula, you can start to edit that formula. For instance, if you noticed a
problem with your parentheses, you click on the input line and you make the changes. If the result
was to your satisfaction, you could click the green check mark to accept the edit. But if it
isn't working for you, just click the red X and you will revert to the previous contents of the cell.
Of course, when you understand how to use spreadsheets to their full power, you will want to build
formulas with cells, not plain numbers, and this is done by using cell addresses. The formulas work
in pretty much the same way, but would look something like this. Equals A2 multiplication, open
parent, B4 plus open parent, D3 multiplication, E3, close parent, close parent. As before, you
multiply whatever is in cell D3 to whatever is in cell E3, take the product, add it to whatever is
in cell B4, then take that sum and multiply it by whatever is in cell 2, A2. Now if A2 happened to
have a 2 in it and B4 happened to have a 3 and D3 happened to have a 4 and E3 happened to have a 5,
it would be exactly the equivalent of our previous example, which was equals 2 multiplication, open
parent, 3 plus open parent, 4 multiplication, 5, close parent, close parent. But as we will see in
a later tutorial, this method using cell addresses is much more powerful and opens up ways of
modeling and doing what if analysis that using simple numbers can never accomplish.
So it pays to get used to using cell addresses to build your formulas. And Calc makes it easy.
If you were to click on a cell, then place your insertion mark on the input line, you could type
the whole formula and that would work. But there is an even easier way. When you are editing a
formula, you can click on another cell and what happens is instead of moving the focus to that cell,
Calc will stay with your formula and simply insert that cell address into the formula.
So I could build my formula this way. First, press the equal sign, then click on cell A2.
Now at this point, my formula will read equals A2, then type an asterisk for the multiplication,
type an open parenthesis, then click on cell B4.
Now it reads equals A2, multiplication, open parent, B4.
I continue, type a plus sign, type another open parenthesis, click on cell D3,
type another asterisk for multiplication, click on cell E3, type a close parenthesis, type another
close parenthesis, click the green check mark to accept my work. Note that when you do this,
the cell you click on when you are doing this is highlighted in a color which helps you to see
what it is you're doing. It really takes longer to describe this than it does to actually do it.
When you get comfortable with building formulas, you may find it very natural and much faster,
but in either way works. So figure out what works best for you. Now this can be an area where that
red X will come in handy. Sometimes you may be working on a formula and then click on a cell
without realizing what you were doing and suddenly you have an errant cell address appear in your
formula. Maybe you had a sudden wish to say, wait a minute, what's in this cell over here?
You click on it to take a look and instead of looking at what's in the cell, you're getting that
cell address stuck in here. One way to get out of this at any point is click the red X to
discard your changes and revert to the previous state. If you click either the red X or the green
check mark, that will always take you out of formula editing mode so that you can now click on
other cells to inspect them without having them added to your formula. One last thing.
If you look at the sum formula we used at the beginning of this tutorial, you may note that inside
the parentheses was the expression B2 colon B13. This denotes a range of cells and is interpreted
as every cell from B2 through to B13 inclusive. So this short hand is a good way to handle a whole
bunch of numbers as long as they are in a contiguous range. So the formula equals sum open
parent B2 colon B13 close parent is precisely the same as equals B2 plus B3 plus B4 plus B5 plus B6 plus
B7 plus B8 plus B9 plus B10 plus B11 plus B12 plus B13. But I think you'll agree it's an awful
lot easier to write this using ranges in the sum function. So with that this is a hookah
signing off for Hacker Public Radio and as always reminding you to support FreeSoftware. Thanks.
You have been listening to Hacker Public Radio or Hacker Public Radio does already.
We are a community podcast network that releases shows every weekday Monday through Friday.
Today's show, like all our shows, was contributed by a HBR listener like yourself.
If you ever consider recording a podcast, then visit our website to find out how easy it really is.
Hacker Public Radio was founded by the digital dog pound and the infonomicum computer cloud.
HBR is funded by the binary revolution at binref.com. All binref projects are proudly sponsored by
lunar pages. From shared hosting to custom private clouds, go to lunarpages.com for all your hosting
needs. Unless otherwise stasis, today's show is released under a creative commons,
attribution, share a life, free dose of life speeds.