add a percentage to an initial value in access

I would like to add a percentage, let's say 10% to each value in a table to the previous value, for example I would like to get the following column:

100 - the first value which is given
110 - which is the first value plus 10%
121 - which is the second value plus 10%
133.1 - which is the third value plus 10%

and so on...
Daniel SerbanescuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Not clear exactly what you want.  Are you looking for a query that does this in new columns?  New rows?  Or do you want to insert new rows into an existing table?  "and so on..." can't go on forever, so when do you want to stop?


»bp
0
Daniel SerbanescuAuthor Commented:
Hi, sorry for not being too specific. I want to update a column in a table where only the first value is set, which is actually an open balance and I want to add the interest for the following rows in the column.
0
Daniel SerbanescuAuthor Commented:
the table will be updated monthly with days from the previous month so the calculation must continue. It would normally last for a year.
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Daniel SerbanescuAuthor Commented:
I am already performing a running sum by day in a query for the same table
0
Pawan KumarDatabase ExpertCommented:
can you send some sample data and the expected output.
0
Daniel SerbanescuAuthor Commented:
the table looks like this

date (as date) |date (as number) |commission (as number)|balance(number)|

30/06/2017     |42916                     |0                                          |100
01/07/2017     |42917                     |45                                        |      I want here 100 +10% = 110
03/07/2017     |42919                     |12                                        |      I want here 110 +10% = 121
05/07/2017     |42921                     |31                                        |      I want here 121+10% = 131.1
06/07/2017     |42922                     |41                                        |

my query looks like this

date (as number) |commission (as number)|running sum for commission | balance
42916                     |0                                          |0                                                   |100
42917                     |45                                        |45                                                |      I want here 100 +10% = 110
42919                     |12                                        |57                                                 |      I want here 110 +10% = 121
42921                     |31                                        |88                                                 |      I want here 121+10% = 131.1
42922                     |41                                        |121

I either want the column Balance in the table to be updated adding 10% to each value or another column in the query with the same figures
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try write a custom function in a Module, like this:

Function GetValue(v As Double, t As Integer, p As Double) As Double
    For i = 1 To t - 1
        v = v + (v * p)
    Next
    GetValue = v
End Function

Open in new window


and then call your query like:

SELECT  a.*, GetValue( 100 , (select count(*) as cnt from yourTable b where b.id <= a.id), 0.1)  as total_110pct
FROM yourTable as a

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Daniel SerbanescuAuthor Commented:
Thank you Ryan, I can't figure out what should I replace "b" with
0
Pawan KumarDatabase ExpertCommented:
You do not have to replace b, just replace "yourTable" with your table name.

b in the query is an alias.
0
Daniel SerbanescuAuthor Commented:
well, I did that in the beginning and when I run the query it asks me for "Enter parameter value b.id" and a.id
0
Daniel SerbanescuAuthor Commented:
ok, I finally figured it out. I've replaced id with the date field. Thank you very much, Ryan, and Kumar.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.