Solved

Scaled multiplier

Posted on 2014-03-06
4
160 Views
Last Modified: 2014-03-09
I have a number in a table. I would like to build a query that will multiply that number by a decimal. The tricky part is the decimal increases based on the value of the number. There are 5 scales

Any part of the number between 0 and 315,000 Multiply by  0.000158730
Any part between 315,00 and 374,000 add the prior part and multiply remainder by  0.000423729
Any part between 374,000 and 480,000 add the prior parts and multiply remainder by  0.000471698
Any part between 480,000 and 585,000 add the prior parts and multiply remainder by   0.000714286
Any part between 585,000 and up add the prior parts and multiply remainder 0.000588235

The number will be anywhere from 0 to 1,000,000. There is only one number to do it to, not like a whole column of numbers. It just needs to be done once. Any idea how I would make this happen?

Thanks!
0
Comment
Question by:cansevin
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39909600
Hi,

You could use this logic to create an UDF

Sub Macro()
myNumber = 999999
Res1 = Min(315000, myNumber) * 0.00015873
Res2 = Min(59000, Max(0, myNumber - 315000)) * 0.000423729
Res3 = Min(106000, Max(0, myNumber - 374000)) * 0.000471698
Res4 = Min(105000, Max(0, myNumber - 480000)) * 0.000714286
Res5 = Max(0, myNumber - 585000) * 0.000588235
Result = Res1 + Res2 + Res3 + Res4 + Res5
End Sub

Function Max(First, Second)
If First > Second Then
    Max = First
Else
    Max = Second
End If
End Function

Function Min(First, Second)
If First < Second Then
    Min = First
Else
    Min = Second
End If
End Function

Open in new window

EDIT

or

Result: IIf([Rec]>=315000;315000;[Rec])*0.00015873+IIf([Rec]-315000>0;IIf([Rec]>=374000;59000;[Rec]-315000);0)*0.000423729+IIf([Rec]-374000>0;IIf([Rec]>=480000;106000;[Rec]-374000);0)*0.000471698+IIf([Rec]-480000>0;IIf([Rec]>=585000;105000;[Rec]-480000);0)*0.000714286+IIf([Rec]-585000>0;[Rec]-585000;0)*0.000588235

Open in new window

Regards
0
 

Author Comment

by:cansevin
ID: 39912757
Thanks! I am trying to use your 2nd option... the long line of code.

Unfortunately when I copy and pasted the code. It says "The expression you entered contains invalid syntax". When I hit "OK", it goes in a highlights the first semi-colon between the two 315000's.

Any idea?

Thanks for your help, much appreciated!
0
 

Author Closing Comment

by:cansevin
ID: 39912980
Thanks!
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39916812
Like you have probably remarked the ; is equivalent of , in my localization

I have forgotten to replace it

Regards
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question