Bobby
asked on
Access 2003, percentage between two fields
I have a table with SellPrice and Cost. I need to find out the percentile difference (Profit) between the two and display it as percent. So, if SellPrice was 100.00 and Cost was 50.00, the Profit would be 50%. No need to show trailing decimals... rounded to the nearest will be fine.
Select SellPrice, Cost, PercentProfit: 100*(SellPrice - Cost)/(Cost) from MyTable
Use Format to display the profit as a percentage:
=Format((SellPrice - Cost) / SellPrice, "0%")
/gustav
=Format((SellPrice - Cost) / SellPrice, "0%")
/gustav
ASKER
Mike, trying yours now but it gets me whacky results. Will post a screenshot...
ASKER
no time for image, going into meetinmg. Your formula is returning my SellPrice with 8 digits and then 2 trailing didgits
borrowing the format from Gustav's solution, try:
Select SellPrice, Cost, PercentProfit: Format((SellPrice - Cost)/(Cost), "0%") from MyTable
Select SellPrice, Cost, PercentProfit: Format((SellPrice - Cost)/(Cost), "0%") from MyTable
There is no way you can obtain those results using the simple formulas posted here.
The Profit should be 24% and 37% respectively.
So correct your SQL to something like this:
and/or post your buggy SQL here.
/gustav
The Profit should be 24% and 37% respectively.
So correct your SQL to something like this:
Select *, Format((SellPrice - Cost) / SellPrice, "0%") As Profit
From YourTable
If you need the numeric value of the profit, use:Select *, (SellPrice - Cost) / SellPrice As Profit
From YourTable
and set the Format property of the field Profit to: 0%and/or post your buggy SQL here.
/gustav
ASKER
gustav,
I think we're close but I'm trying to update a field, not just select and view. Would that change anything in what you've written? I mean, would it still work? Because it isnt when I try to convert your select to an update. The name of the field to update is ProfitPercentage, and I can set it as percent, long int, whatever you think it needs to be.
I think we're close but I'm trying to update a field, not just select and view. Would that change anything in what you've written? I mean, would it still work? Because it isnt when I try to convert your select to an update. The name of the field to update is ProfitPercentage, and I can set it as percent, long int, whatever you think it needs to be.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Damn. I tried both those but now I'm just getting either 1's or 0's, even a few -1's.
0/1 could be possible if your field is integer. -1 is not possible except if you have wigged data.
Perhaps you should upload a sample of your data and query.
/gustav
Perhaps you should upload a sample of your data and query.
/gustav
ASKER
So what should the field size and format be? Maybe thats where Im screwing up, having the wrong combo of both those.
Currency. Always Currency for amounts.
/gustav
/gustav
ASKER
Great! Your results are correct.
The previous of mine must have been mixed up somehow.
/gustav
The previous of mine must have been mixed up somehow.
/gustav
ASKER
Nice!!! Thanks very much Gustav.
You are welcome!
/gustav
/gustav
initial Investment (or cost): 50.00
SellPrice: 100.00
Profit: 100.00 - 50.00 = 50.00
% of profit = Profit / initial investment = 50.00 / 50.00 = 100% not 50%
Is this acceptable?