Calculating Formula (totaling several results)

Discuss the database features
Post Reply
gwasi
Posts: 2
Joined: Mon Aug 13, 2018 9:16 pm

Calculating Formula (totaling several results)

Post by gwasi »

I have 9 items in my table. I am trying to do "Unit" * "Price" for every each items. And that work fine.
-------------------------------------------------------------------------------
My formula is
unit1 * 1price = 1Total
unit2 * 2price = 2Total
unit3 * 3price = 3Total
unit4 * 4price = 4Total

I tried this way to get the total of all of them. But it doesn't work.
This is what I did
1Total + 2Total + 3Total + 4Total nor
(unit1 * 1price)+(unit2 * 2price)+(unit3 * 3price)+(unit4 * 4price).

Please tell me how can I get the total price of all of them?

Title Edited. A descriptive title for posts helps others who are searching for solutions and increases the chances of a reply (Hagar, Moderator).
OpenOffice 4.1.5 on Windows 10
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Please Help Me With Calculating Formula

Post by UnklDonald418 »

If each row in your table has a Unit column and a Price column then
Sum("Unit" * "Price")
should get the value you want.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
keme
Volunteer
Posts: 3699
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Please Help Me With Calculating Formula

Post by keme »

If the suggestion from UnklDonald418 doesn't help you, please tell us exactly how your formula doesn't work.
  • What do you see in the cell?
    How does your results look?
    What formulas do you use? (Please paste the exact formulas you have inyour cells, not the pseudo formulas you have given.)
At best, upload a opy of your file (if it doesn't contain any confidential info).
gwasi
Posts: 2
Joined: Mon Aug 13, 2018 9:16 pm

Re: Please Help Me With Calculating Formula

Post by gwasi »

UnklDonald418 wrote:If each row in your table has a Unit column and a Price column then
Sum("Unit" * "Price")
should get the value you want.
That formula works on each item. But I can't get the total of 9 items.
OpenOffice 4.1.5 on Windows 10
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Calculating Formula (totaling several results)

Post by UnklDonald418 »

If your table is in a Base database, the query would look like this.

Code: Select all

SELECT SUM("Unit" * "Price")  AS "Total" FROM "Your table name goes here"
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
keme
Volunteer
Posts: 3699
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Calculating Formula (totaling several results)

Post by keme »

Sorry, I picked this up from new post and didn't notice that it was in Base. I was thinking Calc.
 Edit: Looks like UnklDonald418 made the same discovery. :super: 
To create a sum in Base, you use the aggregate function SUM.

In design view, enter Unit*Price in the field cell, and select function Sum below.

In SQL view, enter this (assuming the name of your table is "entries":

Code: Select all

SELECT SUM( "units" * "price" ) FROM "entries"
 Edit: UnklDonald's as "Total" gives a cleaner heading to the result, which is good! 
Post Reply