[Solved] Calculated Fields
[Solved] Calculated Fields
Hi, I need to create a simple database, probably only needing one table. My main need to to have some of the fields automatically calculate their values. So, in simple terms, I enter a description, price and purchase date of an item. Now I want the 'current value' field to calculate automatically knowing today's date (in the system) and the purchase date, the price and also knowing the depreciation rule, e.g. 20% per year. I built all this long ago in FileMaker Pro 3 and now I want to rebuild it in a modern database. I can't see any way to do this from the available user information.
Last edited by Hoylander on Thu Nov 27, 2008 12:35 am, edited 2 times in total.
OOo 3.0.X on Mac OSx Leopard
Re: Calculated Fields
Welcome to the forum!
Please search on forum before post, your problem possibly solved and can find it with search facility on right upper corner.
See topic: http://user.services.openoffice.org/en/ ... =13&t=7902
Please search on forum before post, your problem possibly solved and can find it with search facility on right upper corner.
See topic: http://user.services.openoffice.org/en/ ... =13&t=7902
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
Hungarian forum co-admin
Re: Calculated Fields
Thanks, but I did a search on calculated fields before posting and I've just done another one now. There seems to be nothing useful on the subject. There is some complicated stuff about SQL (which I've used with Access databases) but nothing on simple calculations in a field. When I start defining fields, I can choose Text, Number, Scientific, etc, but Calculation... is not an available choice. Does Base in fact support calculated fields in a table? I simply want to do things like calculate a current value from IF(ItemType = D, PurchasePrice*0.6, PurchasePrice*1.03). In words, if the ItemType field contains "D", then current value of item equals the purchase price x 60%, otherwise current value is purchase price x 1.03. I would also want to include time-dependent calculations. Where do I find out how to do such calculations, assuming it's even possible? I could do this in FileMaker Pro 3 ten years ago.
OOo 3.0.X on Mac OSx Leopard
Re: Calculated Fields
You have to create these calculated "fields" in a query, not in a table. (It might work in a view, too, but I'm not sure).
The Built-in_functions wiki page discusses the functions available.
kabing
The Built-in_functions wiki page discusses the functions available.
kabing
NeoOffice (app store version) OpenOffice.org 4.1 and LibreOffice 4.3 on Mac OS X El Capitan
OpenOffice.org 4.1.2 on Windows 10 (Previously on Vista)
OpenOffice.org 4.1.2 on Windows 10 (Previously on Vista)
Re: Calculated Fields
Thanks, Kabing, but I've spent many hours sweating with this and have got nowhere. For practice, I quickly built what I wanted in MS Access (which worked), although I fail to see why calculations only work in Access queries in not in tables. I then tried to replicate the process in Open Office and despite crawling over the limited help pages and the web generally, I got nowhere. In Access I was able to build a function "PresentValue: [UnitPrice]*(1-((Date()-MainTable!AcquisitionDate)/365.25)/[ExpectedLife])", but nothing works in Base. I eventually found the CURDATE() function on the web (instead of Access's Date()), but I could not even get an expression like "CURDATE() - AcquisitionDate" to work in a query. I just got repeated error messages. There's just no way of knowing what I'm doing wrong.
I suppose my conclusion is that Base is not intuitive enough for end users to work with and maybe you already have to be an expert to do anything. That's a shame, as I want to use my Mac and not be forced to use Access on a PC. I could use a new version of FileMaker Pro, but that's a big investment for the simple things I want to do. My 10-year old FileMaker Pro 3 works fine, but the hardware it runs on is not going to last much longer. Maybe somebody will come out with a Base for Dummies one day, or Wiley will produce a Base Bible.
I suppose my conclusion is that Base is not intuitive enough for end users to work with and maybe you already have to be an expert to do anything. That's a shame, as I want to use my Mac and not be forced to use Access on a PC. I could use a new version of FileMaker Pro, but that's a big investment for the simple things I want to do. My 10-year old FileMaker Pro 3 works fine, but the hardware it runs on is not going to last much longer. Maybe somebody will come out with a Base for Dummies one day, or Wiley will produce a Base Bible.
OOo 3.0.X on Mac OSx Leopard
Re: Calculated Fields
If memory serves, calculations with Dates aren't supported in Base. So that may be part of the problem.
Base is the newest of the modules, and you are correct that in many ways it is not particularly user friendly.
kabing
Base is the newest of the modules, and you are correct that in many ways it is not particularly user friendly.
kabing
NeoOffice (app store version) OpenOffice.org 4.1 and LibreOffice 4.3 on Mac OS X El Capitan
OpenOffice.org 4.1.2 on Windows 10 (Previously on Vista)
OpenOffice.org 4.1.2 on Windows 10 (Previously on Vista)
Re: Calculated Fields
Holylander:
Welcome to the world of OpenOffice Base.
I will assume, your database is the 'default' . . . HSQL database engine . . . you can confirm this by looking at the bottom, on the status bar after opening your database file.
Let's break the question down into a few pieces:
I hope this helps, please be sure to let me / us know.
Sliderule
Thanks to add [Solved] in your first post title (edit button) if your issue has been fixed / resolved.
Welcome to the world of OpenOffice Base.
I will assume, your database is the 'default' . . . HSQL database engine . . . you can confirm this by looking at the bottom, on the status bar after opening your database file.
Let's break the question down into a few pieces:
- Functions: to perform 'calculations' besides to +, -, /, * . . . a list and description may be found at either of these two:
- Fields ( sometimes called Column ) names are 'wrapped' in double quotes ( " ) rather than brackets
- A Table stores the atomic data, so, calculations are not stored in the table. But, you can perform the calculations on the data, either with a Query, or, a View -- a pseudo-table -- that does not contain data, but, retrieves data and can perform calculations
- Date / Time calculation: Please see the link below with my explanation, for an example . . . using the function DATEDIFF
http://user.services.openoffice.org/en/ ... 99&p=35447
Code: Select all
[UnitPrice]*(1-((Date()-MainTable!AcquisitionDate)/365.25)/[ExpectedLife])
might look like this in a Query or View:
"UnitPrice" * (1 - (DATEDIFF('day',CurDate(),"AcquisitionDate") / 365.25) / "ExpectedLife")
Sliderule
Thanks to add [Solved] in your first post title (edit button) if your issue has been fixed / resolved.
Re: Calculated Fields
Hi Sliderule - a million thanks, your formula worked (apart from a minor error, easily fixed). The question now is, where can I find a list of all the available functions, including "If this, then that, otherwise that" (conditional function), with their correct syntaxes? Also, I'm finding it quite clumsy to switch between design and view modes. I seem to have to back right out of each mode and then come back in again and right-click to find the edit mode. There's no obvious little mode switching button as in MS Access. Anyway, the main thing is, what I want to is probably possible; it's just a question of how much effort it will take to get there.
Again, many thanks.
Hoylander
Again, many thanks.
Hoylander
OOo 3.0.X on Mac OSx Leopard
Re: [Solved] Calculated Fields
Holylander:
You stated:
You asked:
http://www.hsqldb.org/doc/guide/ch09.html#N1251E
You stated:
Probably have to reverse the order of CurDate() and "AcquistionDate" in the DATEDIFF function . . . I was aware of that when I posted it . . . but . . . I did want you to experiment with it, and, learn from it.Holylander wrote:your formula worked (apart from a minor error, easily fixed)
You asked:
Please reread the post I gave you above . . . and check for CASEWHEN ( one word ) -- just like an IF statement in a spreadsheet ( such as Calc or Excel ), and, a CASEWHEN function may be 'nested' :Holylander wrote:The question now is, where can I find a list of all the available functions, including "If this, then that, otherwise that" (conditional function), with their correct syntaxes?
http://www.hsqldb.org/doc/guide/ch09.html#N1251E
You said:HSQL Documentation:[url]http://www.hsqldb.org/doc/guide/ch09.html#N1251E[/url] wrote:
CASEWHEN(exp,v1,v2)
if exp is true, v1 is returned, else v2
I have no idea what you are talking about if you mean while creating a Query . . . unless you are not using either:Holylander wrote:Also, I'm finding it quite clumsy to switch between design and view modes.
- The button on the Toolbar . . . Switch Design View On/Off
- From the Menu: View -> Switch Design View On/Off
Re: [Solved] Calculated Fields
Hi Sliderule,
You stated:
Probably have to reverse the order of CurDate() and "AcquistionDate" in the DATEDIFF function . . . I was aware of that when I posted it . . . but . . . I did want you to experiment with it, and, learn from it. Indeed, that was the error.
You stated:
Please reread the post I gave you above . . . and check for CASEWHEN ( one word ) -- just like an IF statement in a spreadsheet ( such as Calc or Excel ), and, a CASEWHEN function may be 'nested' : Thanks, I see that everything is explained here.
You quoted this conditional function:
CASEWHEN(exp,v1,v2)
if exp is true, v1 is returned, else v2. This indeed seems to be what I am looking for.
You said:
Hoylander
You stated:
Probably have to reverse the order of CurDate() and "AcquistionDate" in the DATEDIFF function . . . I was aware of that when I posted it . . . but . . . I did want you to experiment with it, and, learn from it. Indeed, that was the error.
You stated:
Please reread the post I gave you above . . . and check for CASEWHEN ( one word ) -- just like an IF statement in a spreadsheet ( such as Calc or Excel ), and, a CASEWHEN function may be 'nested' : Thanks, I see that everything is explained here.
You quoted this conditional function:
CASEWHEN(exp,v1,v2)
if exp is true, v1 is returned, else v2. This indeed seems to be what I am looking for.
You said:
I have no idea what you are talking about if you mean while creating a Query . . . unless you are not using either:Holylander wrote:Also, I'm finding it quite clumsy to switch between design and view modes.
- The button on the Toolbar . . . Switch Design View On/Off
- From the Menu: View -> Switch Design View On/Off
Hoylander
OOo 3.0.X on Mac OSx Leopard