Solved

Scaled multiplier

Posted on 2014-03-06
4
162 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 50

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 50

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

685 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