+ Reply to Thread
Results 1 to 17 of 17

Nested IF Statement

  1. #1
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138

    Nested IF Statement

    Hey everyone. I am working on a resource model for my company. Essentially it is a list of contractors in the company with their daily rates and start and end dates. I have attached a sample spreadsheet.

    As you can see, all the information has already been populated with the cost of each contractor per month (formula used - daily rate*18.83 [days worked per month]). It is also dynamic so if for some reason a contractor end date is changed it needs to be reflected on the cost per month columns (thanks mobidv).

    Now the only issue is that the formula will calculate the cost for a contractor for a full 2 months even if they have only worked for 1.5 months (example of row 4). So basically the formula needs to change so if someone has not worked for the full month, it needs to be reflected in the cost so they are billed only for the number of weeks they worked for the month. Each month is based on 18.83 work days.

    Any help is greatly appreciated.

    Thanks.
    Attached Files Attached Files
    Last edited by FM1; 12-08-2008 at 06:14 AM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    Hello Faraz,

    It's a relatively simple task to calculate up to 15th January only, rather than to the end of the month but to do that you need to know how many workdays there are from 1st to 15th January, how do you calculate that?

    I can't see how you get 18.83 workdays for the entire month, if you were counting just weekdays you'd have +20 I assume, so do you have a 4 day week?

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Perhaps:

    Please Login or Register  to view this content.
    copied down and across


    Eomonth() needs analysis toolpak installed.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138
    Unfortunately, the way this company works, each month is based on 18.83 work days once all holidays have been taken into account (total number of holidays subtracted from 365 and divided by 12). When I first saw this I said to my manager that pretty much assumes that all holidays are spread even over a one year period which is extremely inaccurate. I was told that it was the company policy so I had to work with it.

    If you have any other suggestions I can try draft something up and present it to senior management and hope they will change their minds. I was actually wondering if there is a way to highlight all public holidays, bank holidays, etc in an Excel calendar like you can do on MS Project. If that were possible then I may have a chance of making that work.

    Edit - Thanks NBVC, that formula has worked. Very much appreciated.

    NB - Considering this is a stupid way to setup a resource model, I will try and use a different setup and present it to senior management. To do this, I will need to mark down all UK public holidays so I can use the networkdays formula to accurately forecasts costs. Is there a way to setup a holiday calendar like in MS Project?
    Last edited by FM1; 12-07-2008 at 11:08 AM.

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    If you list all your holiday dates somewhere on the worksheet, e.g. in Z1:Z100then you could use this formula in J3 copied across and down

    =MAX(0,NETWORKDAYS(MAX(J$2,$G3),MIN(EOMONTH(J$2,0),$H3),$Z$1:$Z$100))*$E3*$F3

    I'm assuming that Monday to Friday will be working days and that Saturday and Sunday aren't worked. This would calculate based on the actual number of working days in each month. 18.83 still seems like a low number, that would equate to 35 holidays per year.

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    Quote Originally Posted by NBVC View Post
    Please Login or Register  to view this content.
    Won't that give identical figures for J4 and K4, I thought that the idea was to only give approx half month's cost to January because work finished on the 15th?

    I note also that J1 shows a figure of 13.83, is that a typo?

  7. #7
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138
    Quote Originally Posted by daddylonglegs View Post
    If you list all your holiday dates somewhere on the worksheet, e.g. in Z1:Z100then you could use this formula in J3 copied across and down

    =MAX(0,NETWORKDAYS(MAX(J$2,$G3),MIN(EOMONTH(J$2,0),$H3),$Z$1:$Z$100))*$E3*$F3

    I'm assuming that Monday to Friday will be working days and that Saturday and Sunday aren't worked. This would calculate based on the actual number of working days in each month. 18.83 still seems like a low number, that would equate to 35 holidays per year.
    I have just tried that and it is only returning Value!. I have attached a spreadsheet for your reference. Refer to 'Pilot Version' worksheet.

    Quote Originally Posted by daddylonglegs View Post
    Won't that give identical figures for J4 and K4, I thought that the idea was to only give approx half month's cost to January because work finished on the 15th?

    I note also that J1 shows a figure of 13.83, is that a typo?
    No, it is definitely returning the correct value. Have a look at the attached spreadsheet under Company Method worksheet.

    The reason its showing 13.83 on in J1 is to account for programme shutdown which will only be happening this December.
    Attached Files Attached Files
    Last edited by FM1; 12-07-2008 at 11:32 AM.

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by daddylonglegs View Post
    Won't that give identical figures for J4 and K4, I thought that the idea was to only give approx half month's cost to January because work finished on the 15th?

    I note also that J1 shows a figure of 13.83, is that a typo?
    Yes, correct. We should make colume J relative when referencing J1... as below.

    =IF($H3>J$2,$E3*$F3*J$1,0)*($H3-$G3)/(EOMONTH($H3,0)-(EOMONTH($G3,-1)+1))

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    ......but the K4 figure still calculates as if that was a full month rather than a half month, try changing H4 to 3rd January, isn't the K4 figure too high for only 3 days worked?

    without taking into account specific holidays,, I'd suggest this formula in J3 copied across and down

    =$E3*$F3*J$1*MEDIAN(0,1,($H3-J$2+1)/(EOMONTH(J$2,0)-J$2+1))

    The #VALUE! error with my earlier suggestion is caused because some of your dates wren't recognised as true dates within the holiday range. If you correct that, i.e. enter dates in the format your regional settings requires, then the formula should work as expected

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by daddylonglegs View Post
    ......but the K4 figure still calculates as if that was a full month rather than a half month, try changing H4 to 3rd January, isn't the K4 figure too high for only 3 days worked?

    without taking into account specific holidays,, I'd suggest this formula in J3 copied across and down

    =$E3*$F3*J$1*MEDIAN(0,1,($H3-J$2+1)/(EOMONTH(J$2,0)-J$2+1))

    The #VALUE! error with my earlier suggestion is caused because some of your dates wren't recognised as true dates within the holiday range. If you correct that, i.e. enter dates in the format your regional settings requires, then the formula should work as expected

    I assume you mean change to Jan 3, 2009...that would make 33 days (or 25 Working days).

  11. #11
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138
    Thanks a million for that daddylonglegs. Both formulas are now working. Ill be using the formula you suggested initially (=MAX(0,NETWORKDAYS(MAX(J$2,$G3),MIN(EOMONTH(J$2,0),$H3),$Z$1:$Z$100))*$E3*$F3) as a pilot version which I will be submitting for approval. This will be the easiest way to work instead of assuming an even 18.83 workdays per month.

    Just one last favour to ask. For my own education, are you able to explain the logic behind both formulas in case I need to use it again on another occassion. That way Ill know how to use the formulas and apply logic instead of bugging you guys and hopefully will be able to help others out too.

    Thanks again.

    Edit - How do we change our forum username? I was hoping to have it changed to FM1 if possible.
    Last edited by FM1; 12-07-2008 at 12:35 PM.

  12. #12
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    In this formula in J4

    =MAX(0,NETWORKDAYS(MAX(J$2,$G4),MIN(EOMONTH(J$2,0),$H4),$Z$1:$Z$100))*$E4*$F4

    MAX(J$2,G4) takes the later date from the first of the month or the start date in G4, in this case that's J$2

    EOMONTH(J$2,0) gives the end of the month, i.e. 31st Dec 2008 and so MIN(EOMONTH(J$2),0),$H4) gives the earliest date out of the end of the month date and H$4, which is the end of month, so NETWORKDAYS is just calculating the number of days in the month.

    In a month which is after the work has finished we could get a negative figure from NETWORKDAYS, which we don't want, so the MAX function ensures it's never less than zero

    For the formula in K4 of course the date in H4, 15th January is earlier than the end of the month so the NETWORKDAYS function counts workdays between 1st Jan and 15th Jan.

    The other formula I suggested worked for your examples because all start dates were 1st December but if the start date wasn't 1st of the month it wouldn't work correctly so I'd change that one to

    =$E3*$F3*J$1*MAX(0,(MIN($H3,EOMONTH(J$2,0))-MAX($G3,J$2)+1)/(EOMONTH(J$2,0)-J$2+1))


    EOMONTH(J$2,0)-J2+1 just gives the number of days in the month, e.g. 31 for January

    ...and as in the other formula MIN($H3,EOMONTH(J$2,0)) will give the earliest date from the end of the month or the end date in $H3 and subtract the latest date from the 1st of the month or the start date in G3.

    ..the result is to give the correct fraction of the month

    To change your username I think you'll have to send a PM to our Forum Administrator RoyUK

  13. #13
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138
    Thanks for the explanation mate. Very much appreciated.

    Edit - Uploaded the final version of the spreadsheet with the formulas in case someone else might need it for their reference.
    Attached Files Attached Files
    Last edited by shg; 12-07-2008 at 04:15 PM. Reason: removed spurious quote

  14. #14
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138
    Sorry to bump the thread but Im having some issues with the spreadsheet. If I change the End Date (column H), it returns a #NAME? value. I have tried tracing the error and checking calculation steps but I cant seem to find the problem.

    Again, any help is greatly appreciated.

  15. #15
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    Which sheet was that, pilot or current (or both)?

    I tried changing dates on both versions of your attached sheet. It worked OK for me. Obviously make sure you input valid dates and that Analysis ToolPak is installed (for NETWORKDAYS and EOMONTH functions to work)

  16. #16
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138
    Quote Originally Posted by daddylonglegs View Post
    Which sheet was that, pilot or current (or both)?

    I tried changing dates on both versions of your attached sheet. It worked OK for me. Obviously make sure you input valid dates and that Analysis ToolPak is installed (for NETWORKDAYS and EOMONTH functions to work)
    Well it looks as though Im a complete idiot. I transferred the formula to a new spreadsheet which didnt have the analysis tookpak enabled.

    Sorry about that and thanks again.

  17. #17
    Forum Contributor
    Join Date
    12-13-2007
    Posts
    138
    Edit - please disregard. Stuff with my actual excel program.
    Last edited by FM1; 12-19-2008 at 06:27 AM.

+ 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