complex date count formula help

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,005
Office Version
  1. 365
Platform
  1. Windows
i can't seem to get my head around this formula. i have a range of project data where each record has start, end, and change dates. Some of these records begin prior to the start of the financial year and some start within the financial year and then end after the end of the fin year. The change dates represent a change in responsibility for the project. For each project with a change date, a new line is entered with the new details but still the original start and end dates. For the first Project below, there are multiple changes, with the change date representing the date of the change. Each change/new line I have given a line number using a simple formula which increases by 1 if the project number appears in the cell above.
Rich (BB code):
Order data byProj Nbr
1Start DateFin Yr End30/06/2019
Change DateFin Yr Start1/07/2018
ABCDEFGHIJ
Record List NbrREPORTING_MONTHProj NbrStart DateEnd DateTRANS_DATE_INTRANS_DATE_OUTChange DATEIn YearIn Year By Day
1B937866-1229/06/20186/07/201829/06/20186/07/201829/06/201850
2B937866-1229/06/20186/07/201829/06/20186/07/201830/06/201800
3B937866-1229/06/20186/07/201829/06/20186/07/20181/07/201800
4B937866-1229/06/20186/07/201829/06/20186/07/20182/07/201801
5B937866-1229/06/20186/07/201829/06/20186/07/20183/07/201801
6B937866-1229/06/20186/07/201829/06/20186/07/20184/07/201801
7B937866-1229/06/20186/07/201829/06/20186/07/20185/07/201801
1B937866-137/08/201810/08/20187/08/201810/08/20187/08/201831
2B937866-137/08/201810/08/20187/08/201810/08/20188/08/201801
3B937866-137/08/201810/08/20187/08/201810/08/20189/08/201801
<tbody> </tbody>

In column I, I count the total number of project days within the financial year. the result is aligned to the first record number for each project using this formula:

Rich (BB code):
=IF(A6>1,0,IF($D6<>$E6,MAX(0,MIN($E6-1,$I$2)-MAX($D6,$I$3)+1),IF(AND($D6=$E6,$D6>=I$3,$E6<=I$2),1,0)))

this says, if A is not 1 (the first project record), return 0.

if A contains 1, and the start and finish dates are not the same, then compare start and finish dates of the project with the beginning and end dates of the fin year, and return the difference (which is either an amount in year or zero if the start and end dates are outside of the fin year).

if the project started and finished on the same day, and is within the fin year, we allocate 1 day.

all good.

the problem i am having is actually identifying which changes are within the fin year based on the change dates. So, i thought i would use the same methodology as I used to get total project days within the year.

Rich (BB code):
=IF($D6<>$E6,IF(AND($A6=1,$A7=1),MAX(0,MIN($G6-1,$I$2)-MAX($F6,$I$3)+1),IF(AND($A6=1,$A7>1),MAX(0,MIN($H7-1,$I$2)-MAX($H6,$I$3)+1),MAX(0,MIN($H6-1,$I$2)-MAX($H5,$I$3)+1))),IF(AND($D6=$E6,$D6>=I$3,$E6<=I$2),1,0))

I don't need to put the values only on the first line of each project so that initial part is gone. (If(A6>1,0)

please bear with me.

if start and end dates are different then

if(AND($A6=1,$A7=1) ..... identify whether a new project starts on the line below: if it does use the change dates in and out (Trans Date In and Trans Date Out above) compared to the fin year dates to determine whether or not that single line project's days are counted

BUT

IF(AND($A6=1,$A7>1) ..... if this is the first line of a multi line project (ie has changes), we need to use the change dates to count the days.

so once again, compare to the fin year dates... MAX(0,MIN($H7-1,$I$2)-MAX($H6,$I$3)+1) where H7 is the date of the next change and H6 is the date of this change. so for the first line of a project, the change date = start date.

then, if IF $A6<>1 or this is a subsequent line in the project, compare this change date to the previous one, and if they fall within the fin year, rack em up.

the flip side of the initial If statement, where Start and End dates are the same, so long as these dates are within the fin year, add 1.


the problem is, with my multi line projects, where the change falls on the start of the fin year (first project line 3), i am getting 0.

someone save me please. where do i adjust the formula to account for these without losing any others or gaining ones i don't want?

it might help to know, project rules stipulate that we count days by the end date. that is, if a project starts on 2 August and finishes on 3 August, its counted as only 1 project day. Starting and finishing on the same day is 1 project day. In context, if a project started 29/06/2018 (Project 1) and ended 5 July 2018, we count July 1 to 5 each as a day, so 5 project days within the fin year. If however, a project started 30/6/2019, the end of the fin year, no days would be counted until next year.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I know it seems complex, however, its just a nested if problem.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,388
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top