+ Reply to Thread
Results 1 to 9 of 9

Deduct Percentage if Value In Between

  1. #1
    Registered User
    Join Date
    05-30-2012
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    6

    Deduct Percentage if Value In Between

    Hey guys,

    I need some help with this query, I'm not quite sure what would be the most efficient / easiest way of doing so.

    I have the following query:
    2w32syt.png
    \1
    hv2mx4.png
    \1

    Okay so what I want to be able to do if MINUS a certain percentage from GrossPay if the GrossPay is in between 2 certain values.

    For example, if GrossPay were inbetween $400 and $500 (including ($400 and $500) deduct 10% from the GrossPay.
    I would like to make a table of values in between and percentages.

    Eg values inbetween:
    2iurkg1.png
    \1

    How could I create another table, so that for example when I wanted to change the deduction rate of $400 to $501 I could do so just by changing a eg a value in a Field in a table, instead of changing all this code in a query IIf statement.

    Or will I just have to hard code this as an IIf statement in a query, and whenever I want to change the percentage deduction of a certain value I will just have to edit this code. I am really hoping that I could avoid this, as I prefer the table approach which would allow me to change percentages on the fly.

    Thanks
    Last edited by TehNoob2010; 08-14-2012 at 07:52 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: Deduct Percentage if Value In Between

    Assume:
    Cell A1 = Gross Pay
    Cell A2 = lower limit {In this case,$400}
    Cell A3 = upper limit {In this case,$500}
    Cell A4 = deduction percentage {In this case,10%}


    =IF(AND(A1>=A2,A1<=A3),A1*(1-A4),"")
    Click on star (*) below if this helps

  3. #3
    Registered User
    Join Date
    05-30-2012
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    6

    Re: Deduct Percentage if Value In Between

    Quote Originally Posted by K m View Post
    Assume:
    Cell A1 = Gross Pay
    Cell A2 = lower limit {In this case,$400}
    Cell A3 = upper limit {In this case,$500}
    Cell A4 = deduction percentage {In this case,10%}


    =IF(AND(A1>=A2,A1<=A3),A1*(1-A4),"")

    I've decided to take the hardcode approach of the IIf statement. I guess I won't really be needing to change the deduction values.

    Okay now to my request, how would I do an IIf statement like this?

    x=GrossPay btw

    If
    x>=400 but x<500
    Then
    10%
    Else
    x >= 500 but x<600
    Then
    15%

    Etc, etc

  4. #4
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: Deduct Percentage if Value In Between

    =if(and(gross_pay>=400,gross_pay<=500),gross_pay*.10,if(and(gross_pay>=501,gross_pay<=600),gross_pay*.15,""))

  5. #5
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Deduct Percentage if Value In Between

    How about

    =IF(INT(gross_pay/100)=4,gross_pay*0.1,IF(INT(gross_pay/100)=5,gross_pay*0.15,""))

  6. #6
    Registered User
    Join Date
    05-30-2012
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    6

    Question Re: Deduct Percentage if Value In Between

    Quote Originally Posted by Cutter View Post
    How about

    =IF(INT(gross_pay/100)=4,gross_pay*0.1,IF(INT(gross_pay/100)=5,gross_pay*0.15,""))
    Okay now I've checked and I have to put these values and deductions in a table.

    So could I make a table with each


    tblDeductions

    Lower----Upper----Percentage
    300------400------10%
    401------500------12%
    501------600------15%
    600------700------18%
    701------800------20%

    So how could I do so if I had a table above. And if the Gross Value were in between Lower and Upper to return that percentage.

  7. #7
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Deduct Percentage if Value In Between

    You've changed your limits from post #3, but using the values in post #6:

    Assuming gross pay in cell A1 and table in AA1:AC6

    =A1*LOOKUP(A1,AA2:AA6,AC2:AC6)

    Make sure you set your limits with cents in mind

  8. #8
    Registered User
    Join Date
    05-30-2012
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    6

    Re: Deduct Percentage if Value In Between

    Quote Originally Posted by Cutter View Post
    You've changed your limits from post #3, but using the values in post #6:

    Assuming gross pay in cell A1 and table in AA1:AC6

    =A1*LOOKUP(A1,AA2:AA6,AC2:AC6)

    Make sure you set your limits with cents in mind

    So if the GrossPay, calculated in the original query is inbetween any of these two values, return the percentage and call the field PercentageReduction. Then I can just easily do another field in the query and easily calculate GrossPay - (PercentageReduction/100)

    \1

  9. #9
    Registered User
    Join Date
    05-30-2012
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    6

    Re: Deduct Percentage if Value In Between

    Is there a way I could do this without SQL?

    Because I have very little knowledge with SQL.

    If it helps, here is the Access file.
    I use Access 2010.

    http://www.mediafire.com/download.php?j122lhs4wc7ndol


    Okay I'm not sure with SQL, but if you look on my file above, the GrossPay (PayRate * Hours) is in a Query called qryStaff.

    So I tried:

    Please Login or Register  to view this content.
    But it did not work. :S Why is that?

    Yes I know that it's not in percentage form, I just want to test if it actually works first.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1