Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Percent 5

Status
Not open for further replies.

katiekat

Technical User
Jun 6, 2000
300
US
I have a table that holds parts info and costs, and a feild that totals the cost. I have to add a markup percentage as a line item to this total. Is there some way to do this within a form? Or within the underlying query/report?

I saw some formulas that looked like this:

[number1]/[number2]*100

but I'm not sure how to apply it.

Thanks in advance for the help!!!
Kate Holy tek-tips batman!:-0
 
To do it in a report, just create an unbound text box and type your formula in the "Control Source" property box for the text box (put "=" in front of the formula. If you have trouble, click the "..." box to bring up the Expression Builder.

You can also set the format to display it as a percent.

To put it in a query, type:

"MyPercent:=[number1]/[number2]*100"

Where "MyPercent" is the name you want for the query field.


 
In addition to GDGarth's comments you may want to control the decimal places that are displayed. To do that the Format statement helps:

MyPercent: Format([number1]/[number2]*100, "0.00")

This will give you a 2 decimal place display of the percentage Bob Scriver
 
Thanks!

I just have one potentially stupid question.

What is Number1 and number2? I assume that one would be the total cost feild. What is the second?

I'm sorry, I'm sure it's easy.

Thanks again! Holy tek-tips batman!:-0
 
If your cost is calculated into a field called "cost" then create a text box called percentage and put the code in the control source:

=[cost]/10

so if the cost is 100.00..it will calculate
100/10 or 10.00 dollars. (if it's a 10 percent markup)

you can then run a total field by putting the control source of another box to be =[cost]+[percentage]

it will autocalculate....since these are formulas in the form however, they will not appear in the table.

Hope this helps!

 
Thank you soooo much! This is exactly what I was looking for!

:) Holy tek-tips batman!:-0
 
Just to let any future readers of this post know, here was my solution:

I made an unbound texbox in the footer of my form, and added this to the "control source"

=[gtotal]*0.15

Where gtotal is the feild with my cost total. I couldn't get the formatting to work. :( Maybe someone else will, and post it up here for me to look at.

Thanks again everyone! Holy tek-tips batman!:-0
 
The easiest way to get the formatting to work is to just change the format of your text box. It looks to me like instead of "Percent", you may want Currency formatting. In any case, there are plenty of standard formats available.

Open the report in design mode, right click on the text box and choose "Properties". Under the "Format" tab, click on "format". There's a drop down menu that lists a whole bunch of standard formats, including dates, currency, percent, and others.

The added advantage is this changes the format without converting the data to a string, so you can still do calculations easily.

 
The previous posts have been excellent. However, there is one additional point to consider. Harken back to your days as a high school algebra student, and you will recall that it is not possible to divide by zero. Computers generally freak if you attempt to divide by zero. With that in mind, you might consider this option:

MyPercent: iif([number2]=0, 0.00, Format([number1]/[number2]*100, "0.00"))

Now, this will give you the wrong answer if the divisor is zero. However, the right answer is to print an ugly error message. Many users prefer to see a zero. Another possibility is to return "N/A" if the divisor is zero. That is more accurate, but then you don't know whether the final output will be text or a number.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top