Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Scaled multiplier

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
cansevin
Asked:
cansevin
  • 2
  • 2
1 Solution
 
Rgonzo1971Commented:
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
 
cansevinAuthor Commented:
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
 
cansevinAuthor Commented:
Thanks!
0
 
Rgonzo1971Commented:
Like you have probably remarked the ; is equivalent of , in my localization

I have forgotten to replace it

Regards
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now