简体   繁体   中英

Calculate EndDate using a formula on Excel

So i'm trying to write a formula that gives me an endDateTime to a project knowing just two things:

  1. startDate;
  2. How many hours it will take to finish the project;

The problem here it is that i cannot use vba just the ordinary excel formulas.

I tried to use =WORKDAY.INTL(date,days,"workingDaysPattern",holidaysTable) but my problem is that one of the premises is that workingTimePerDay is a variable too.

Example:

startDateTime => 29 November 2016 at 10:00 and it will take 125 hours to complete.

Every Monday i have 2 hours to work;

Tuesday 3 hours;

Wednesday 8 hours;

Thursday 10 hours;

Friday 5 hours;

Saturday 12 hours;

Sunday 0 hours;

Giving a total of 40 hours. Ok, i could calculate average and say that it will take 3 weeks and 0,125 of a week. Then i just have to sum it up until i make the expected result, but... since i don't have a "while" or any kind of cycle i don't know how to get there. Also because i have to respect the holidays so i cannot just build an array formula like:

{=SUM(CHOOSE(WEEKDAY(ROW(INDIRECT(date1&":"&date2))),1,2,3,4,5,6,7))}

Any thoughts?

Ok. i got it. Just in case if someone needs this. (i doubt it) the things we know:

  • StartDate ; TaskWorkingHoursNeeded ; WorkingHoursPerDay ; HolidaysTable

First we create a table with working days respecting WEEKDAY function . Because we know the total working hours per week (summing WorkingHoursPerDay ), calculate the total working weeks (exceeded):

ExceededWorkingWeeks = CEILING(TaskWorkingHoursNeeded/WorkingHoursPerWeek;0)

Second, if it was just like that, in how many days (exceeded):

ExceededWorkingDays = exceededWorkingWeeks / countDaysWhereExistWorkingHours

Third, in how many hours (exceeded):

ExceededWorkingHours = ExceededWorkingWeeks * WorkingHoursPerWeek

So, now we can calculate the exceeded end date if we were using ExceededWorkingDays not forgetting the holidays and the days of a week that we work ( Resource ):

ExceededEndDate = WORKDAY.INTL(StartDate, ExceededWorkingDays, "patternWorkingWeekDays", HolidaysTable)

Now the "ugly" part. A lot of if's and else's and we are done.

For 7 value positions starting 0 till 6 first we calculate the day subtracting value day to ExceededEndDate . Then to know if this day matters we calculate if this is a working day on our patternWorkingWeekDays and it is not a holiday:

CheckWorkDay = NETWORKDAYS.INTL(ValueNewDate;ValueNewDate;"patternWorkingWeekDays";HolidaysTable)

If returns 1 it means that the hours of this working day are to subtract to ExceededWorkingHours . Calculate weekday using a "index alignment":

ValueNewWeekDay = 7-MOD(ABS(value+(7-WEEKDAY(ExceededEndDate)));7)

Using this ValueNewWeekDay for indexing to the table with my working days i could know how many hours i have to subtract to CurrentExceededWorkingHours .

For each working day, not holiday, subtract working hours to CurrentExceededWorkingHours until we get CurrentExceededWorkingHours < TaskWorkingHoursNeeded . Of course checking for each value if ValueNewDate is lower than StartDate .

Like the client wanted we can put all this formulas in just one cell.

RESUME:

Real end date is calculated by subtracting for a week (7 days) the exceeded hours.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM