Summing currency fields in base

I have three currency fields - 'Fee1', 'Fee2' and 'Total'. How do I add fee1 and fee2 together and put the result automatically into the Total field?

TIA
Adam.

In field 3
=field1+field2

Thanks Wade, but where do I put that?

If A1 is fee1
fee2 is B1
then in
c1 you type
=A1+B1

You do realize the question is about base, not calc?

Ah, sorry. I cant see the whole subject line
on my phone. Though a quick search on
calculated fields shows you can:

http://sheepdogguides.com/fdb/fdb1calcf1.htm

Adam,

I am not sure where you are wanting this total. There may be other methods to do this, but I prefer to do this calculation in a query. I use separate queries for reports and forms so a change in one does not affect the other. First, you need to create a query, if you have never created a query, then there is a learning curve you need to go through to create one. You could start by using the wizard to create the query and then save it and quit it. Then you can edit it in "Design Mode". Once in the Design mode, you can verify that your table is in the upper frame and your table field names are in the lower frame with the "Visible" block checked. This will get you what you have now and you can build on it. You need to add a field to the bottom frame with your formula in the "Field" block. For your example, it would look likeĀ  "(fee1+fee2)" (no quotes). You probably don't need the parens either, but it is safe. Then, in theĀ  "Alias" block of this new column, you need to add your new field name. In your example, it would be "Total" , again no quotes. Make sure the "Visible" block is checked or the total result will not be passed out of the query. If you already have a "Total" field in your table, then you need to have another, unique, name.

Then you need to have your form attach itself to the query rather than the table. You do this by opening the form in "Edit" mode and selecting the "Form" icon. At this time, you should have a popup called "Form Properties". Select the "Data" tab and in the "Content type" list select "Query". Then select your new query in the "Content" list. Then you can add the new "Total" field to your form. Doing so in a report is similar.

This is just a short description. You should be familiar with LO queries to do this. All of this may be documented well by now. So, read up on it if you want to create a query.

Note: One should never have calculated fields in a database. It wastes space.

Note also that I am using Mariadb (MySQL). If you are using the LO bundled database server, then this may be different.

HTH.

Girvin

Adam,

From an DB administrator/designer's perspective, calculated field values
are not generally stored in the database if they don't need to be. A
view might solve your problem in this case, as a view is a kind of fixed
query. It should be possible to create a view that calculates the sum of
your two fields and then show that in a column of the view as the result
or total.

Alternatively, you could define a query that would calculate the total
value for you, but it wouldn't insert that value into a field
specifically designed to store the value (display only).

If you do want to insert the actual total value into a field so that it
is stored in the database table, then you would probably need to define
a trigger (or stored procedure) that performs the calculation each time
a change is made to either Fee1 or Fee2, or upon some other condition.

You don't say, however, which kind of db engine you are using and
triggers are not available for all database sources supported by LOBase
(for example Calc, CSV, text tables, Dbase).

If you didn't want to perform this automatic calculation and storage at
the database engine level, but at a user interface level, then you could
use a Basic macro to effect the calculation, insert the total value and
refresh the table/form after insertion.

Alex

I am not sure where you are wanting this total.

I want it in the same form as fee1 and fee2.

First, you need to create a query,

I'm familiar with this.

Then you need to have your form attach itself to the query rather than the table. You do this by opening the form in "Edit" mode and selecting the "Form" icon. At this time, you should have a popup called "Form Properties". Select the "Data" tab and in the "Content type" list select "Query". Then select your new query in the "Content" list. Then you can add the new "Total" field to your form.

When I try to add the field using the Add Field icon LO crashes without fail. Is there a way around this?

Thank you for your help Girvin.

Perhaps you need to begin over as far as you fields are concerned. First of all, you only need two fields in the table: Fee1 and Fee2. You also need a primary key which is listed first. Fee1 and fee2 need to be given the properties you want for them. The primary key has to have "entry required" selected. I prefer it to also have this property: INTEGER. Save the table. When I did this, I named the table, Currency, and the primary key, ID.

Second, create a query in SQL View. Use this SQL statement:

SELECT "ID", "Fee1", "Fee2", "Fee1" + "Fee2" AS "Total" FROM "Currency"

Save the query giving it a name other than Currency. (You can not have a table and query with the same name.)

Running the query, the ID field has <AutoField>. You can not enter values for Fee1 and Fee2. Typing <ENTER> after entering values for Fee1 and Fee2 will place the sum in the Total column.

Now you can either use the Form wizard to create a form from the query or use Girvin's suggestion for connecting your present form to the query.

Dan