+ Reply to Thread
Results 1 to 15 of 15

Excel 2007 : If, and, or

Hybrid View

  1. #1
    Registered User
    Join Date
    01-19-2011
    Location
    Darlington, Englad
    MS-Off Ver
    Excel 2007
    Posts
    7

    Smile If, and, or



    Hi there, I am currently doing some work where by I need to forecast projected salaries from 2011-15 (assuming nothing bad happens on 21/12/12 lol!)

    We have 3 departments, each with 4 PayBands so in total there are 12 different paybands.

    The pay goes up after so many years service, so less than 4 years is Band 1, 4-7 years Band 2, 8-12 years Band 3 and 13+ Band 4.

    I can not seem to get my head around this (I have done this from scratch so I have not had anything to work from.

    This is what I am trying to say

    IF(AND(C2="Production", EMPLOYEES!M2="G1", IF(DATEDIF((D2,"31/12/2011","y")<=3), RATES!$D$10,
    IF(AND(C2="Production",EMPLOYEES!M2="G2", IF(DATEDIF((D2,"31/12/2011","y")<=7), RATES!$D$11,
    IF(AND(C2="Production", EMPLOYEES!M2="G3", IF(DATEDIF((D2,"31/12/2011,"y")<=12), RATES!$D$12,
    IF(AND(C2="Production", EMPLOYEES!M2="G4", IF(DATEDIF((D2,"31/12/2011","y")>13), RATES!$D$13,

    IF(AND(C2="Design", EMPLOYEES!M2="G1", IF(DATEDIF((D2,"31/12/2011","y")<=3), RATES!$D$6,
    IF(AND(C2="Design",EMPLOYEES!M2="G2", IF(DATEDIF((D2,"31/12/2011","y")<=7), RATES!$D$7,
    IF(AND(C2="Design", EMPLOYEES!M2="G3", IF(DATEDIF((D2,"31/12/2011,"y")<=12), RATES!$D$8,
    IF(AND(C2="Design", EMPLOYEES!M2="G4", IF(DATEDIF((D2,"31/12/2011","y")>13), RATES!$D$9,

    IF(AND(C2="Admin", EMPLOYEES!M2="G1", IF(DATEDIF((D2,"31/12/2011","y")<=3), RATES!$D$2,
    IF(AND(C2="Admin",EMPLOYEES!M2="G2", IF(DATEDIF((D2,"31/12/2011","y")<=7), RATES!$D$3,
    IF(AND(C2="Admin", EMPLOYEES!M2="G3", IF(DATEDIF((D2,"31/12/2011,"y")<=12), RATES!$D$4,
    IF(AND(C2="Admin", EMPLOYEES!M2="G4", IF(DATEDIF((D2,"31/12/2011","y")>13), RATES!$D$5,
    IF(EMPLOYEES!M2="G4", IF(DATEDIF((D2,"31/12/2001","y")=20), RATES!$D$5*1.008, "ERROR"

    I have a working formula for working out what grades staff will be this year, next year any advice!!? Really really appreciated

    Thanks

    Chris

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Problems with IF, AND, OR

    You clearly have 3 departments.

    Do you have
    1/. 4 Grades, each sub-divided into 4 bands based on years of service for each department?
    or
    2/. is each Grade, in any department, attained by years of service.

  3. #3
    Registered User
    Join Date
    01-19-2011
    Location
    Darlington, Englad
    MS-Off Ver
    Excel 2007
    Posts
    7

    Red face Re: Problems with IF, AND, OR

    Hi there, thanks for getting back to me.

    Each Dept. has its own salary based on grade.

    When I use this;

    IF(AND(D2="Production", DATEDIF(E2,"31/12/2011","m")<48, F2="G1"),RATES!$D$10,
    IF(AND(D2="Production", DATEDIF(E2,"31/12/2011","m")<96, F2="G2"),RATES!$D$11,
    IF(AND(D2="Production", DATEDIF(E2,"31/12/2011","m")<156, F2="G3"),RATES!$D$12,
    IF(AND(D2="Production", DATEDIF(E2,"31/12/2011","m")>156, F2="G4"),RATES!$D$13,
    IF(AND(D2="Production", DATEDIF(E2,"31/12/2011","m")>=240, F2="G4"),RATES!$D$13*1.008,

    IF(AND(D2="Design", DATEDIF(E2,"31/12/2011","m")<48, F2="G1"),RATES!$D$6,
    IF(AND(D2="Design", DATEDIF(E2,"31/12/2011","m")<96, F2="G2"),RATES!$D$7,
    IF(AND(D2="Design", DATEDIF(E2,"31/12/2011","m")<156, F2="G3"),RATES!$D$8,
    IF(AND(D2="Design", DATEDIF(E2,"31/12/2011","m")>156, F2="G4"),RATES!$D$9,
    IF(AND(D2="Design", DATEDIF(E2,"31/12/2011","m")>=240, F2="G4"),RATES!$D$9*1.008,

    IF(AND(D2="Admin", DATEDIF(E2,"31/12/2011","m")<48, F2="G1"),RATES!$D$2,
    IF(AND(D2="Admin", DATEDIF(E2,"31/12/2011","m")<96, F2="G2"),RATES!$D$3,
    IF(AND(D2="Admin", DATEDIF(E2,"31/12/2011","m")<156, F2="G3"),RATES!$D$4,
    IF(AND(D2="Admin", DATEDIF(E2,"31/12/2011","m")>156, F2="G4"),RATES!$D$5,
    IF(AND(D2="Admin", DATEDIF(E2,"31/12/2011","m")>=240, F2="G4"),RATES!$D$5*1.008, "ERROR!")))))))))))))))

    I seem to get the right payments for that year based on the data I have.

    Trouble is - those who have 20 years service are getting a 0.8% increase on their annual salary (tight people!) but this part;

    IF(AND(D2="Admin", DATEDIF(E2,"31/12/2011","m")>=240, F2="G4"),RATES!$D$5*1.008, "ERROR!")))))))))))))))

    Doesn't work - please accept my apologises, I am a complete N0013 to Excel and Access.

    Thanks for your time and advice in advance

    Chris

  4. #4
    Registered User
    Join Date
    01-19-2011
    Location
    Darlington, Englad
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Problems with IF, AND, OR

    Quote Originally Posted by Marcol View Post
    You clearly have 3 departments.

    Do you have
    1/. 4 Grades, each sub-divided into 4 bands based on years of service for each department?
    or
    2/. is each Grade, in any department, attained by years of service.
    Yes to Number 1 mate

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Problems with IF, AND, OR

    From what I can tell you'd be far better off splitting the calculation.

    For sake of ex.

    G2: 
    =DATEDIF(E2,"31/12/2011","y")
    At which point something along the lines of:

    H2:
    =IF(AND((RIGHT($F2)+0)=MATCH($G2,{0,4,7,13}),OR($D2={"Admin","Design","Production"})),INDEX(Rates!$D$2:$D$13,RIGHT($F2)+4*(MATCH($D2,{"Admin","Design","Production"},0)-1))*(1+0.008*($G2>=20)),"Error")
    that said a basic rate table would help simplify things somewhat...

    The complexity of the above stems from the fact that you seemingly need to first validate the legitimacy of the Dept and the Band when compared to Years of Service (ie to catch "Error")
    Last edited by DonkeyOte; 01-19-2011 at 03:03 PM. Reason: 0.008 rather than 0.08

  6. #6
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Problems with IF, AND, OR

    As far as I can understand, even when the DATEDIF is > 240, the formula always stops at f.i.
    IF(AND(D2="Production", DATEDIF(E2,"31/12/2011","m")>156, F2="G4"),RATES!$D$13
    , in one of the three groups,any value larger than 240 would de facto be larger than 156, so this test returns TRUE and the ,8% is never calculated

    Maybe inverting the last two IF's ( for the three groups) would solve the problem?

    Naturally DO's formula would be more efficient

  7. #7
    Registered User
    Join Date
    01-19-2011
    Location
    Darlington, Englad
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Problems with IF, AND, OR

    Whoa - its blown me right out of the water there like!

    I do apologise for being so simple over these matters, if I upload the test file could you have a look at it and give me some pointers?

    I do honestly really appreciate any help - I just can not get it to work

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Problems with IF, AND, OR

    Quote Originally Posted by TheBoyBest View Post
    if I upload the test file could you have a look at it and give me some pointers?
    Yes, that would be a good idea.

  9. #9
    Registered User
    Join Date
    01-19-2011
    Location
    Darlington, Englad
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: If, and, or

    OK........... Again, kudos to all you people who can help - I am hoping to learn a lot from this so please accept my thanks.

    Attached sheet for work;

    Overview

    There are 4 grades of pay based on length of service

    G1 = less than 4 years
    G2 = 4-7 years
    G3 = 8-12 years
    G4 = 13+ years

    Staff grade progression starts in the month they meet the above criteria from their start date

    Salaries are standard and increase 1% each year in January

    From this August we will be celebrating the 20th Anniversary and we are going to include a 20 year long service award to all staff when they reach 20 years service. This "bonus" is going to be 0.8% of their salary in that year.

    We need the spreadsheet to forecast costs till 2020

    There! Sigh (bitten off more than I can chew, but they will insist on making self-learn this stuff!)

    Many many thanks

    Chris
    Attached Files Attached Files

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If, and, or

    So quickly.. using your example

    My first suggestion was to store the Years Service separately, eg:

    K2:
    =DATEDIF($C2,"31/12/2011","y")
    copied down to K31
    Then, to generate rates:

    F2:
    =IF(AND((RIGHT($D2)+0)=MATCH($K2,{0,4,7,13}),OR($B2={"Admin","Design","Production"})),INDEX(RATES!D$2:D$13,RIGHT($D2)+4*(MATCH($B2,{"Admin","Design","Production"},0)-1))*(1+0.008*($K2+(COLUMNS($F2:F2)-1)>=20)),"Error")
    applied to matrix
    which would for F2 generate 32,259.90 given 20 years service
    (ie 1.008 of 32,003.87)

    The above is adapted slightly from before in so far as reference to Rates becomes relative such that copied to the right in picks up the correct column... similarly the years service is incremented by one each year such that the increase occurs where appropriate.
    (we only conduct the Gn = years service test for 2011 - thereafter the calculation is not viable)

    You will note that rows 16:18 return Error - because years service (13) exceeds the G3 band (same issue re: 24:26 [should be G3] and 28 [should be G2])

  11. #11
    Registered User
    Join Date
    01-19-2011
    Location
    Darlington, Englad
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: If, and, or

    Hi thanks for the quick reply - I am not sure I follow entirely. To paraphrase Doc McCoy - "I'm a bricklayer, not a Doctor, Jim"!

    Someone at work was banging on about lookup tables? Are they any good? I'm really stressed hence doing this in my own time, at 2220hrs!

    Cheers

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If, and, or

    All you need to do is copy the formulae I gave you into the cells specified and you have the results. I'm not sure what else I can add at this stage.

  13. #13
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: If, and, or

    I had to go and have perhaps lost the current status of this thread.

    FWIW
    I had started a sample workbook

    The result uses named ranges and I think perhaps a simpler and more flexible rates table.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If, and, or

    @Marcol, re: your model, I'm probably wrong but the below:

    Quote Originally Posted by TheBoyBeast
    From this August we will be celebrating the 20th Anniversary and we are going to include a 20 year long service award to all staff when they reach 20 years service. This "bonus" is going to be 0.8% of their salary in that year.
    would imply that the one off multiplier could occur at any point within the forecast.

    For the above reason I had used:

    *(1+0.008*($K2+(COLUMNS($F2:F2)-1)>=20))
    however that too is incorrect given it's a one off & should be =20 rather than >=20

    Attached is the OP's last file with my suggestions
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    01-19-2011
    Location
    Darlington, Englad
    MS-Off Ver
    Excel 2007
    Posts
    7

    Thumbs up Re: If, and, or

    Hi there - thanks for your help - I seem to have sorted it using your advice so its really appreciated thanks

    Chris

+ 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