Complicated Date Range Formula?

Iain69

New Member
Joined
Jul 5, 2012
Messages
8
Hi All, found this site when searching for the answer to an excel problem I am facing.

We need to track the number of days per calendar year an expat stays in this location and am trying to build a spreadsheet to track these days accurately from just entering arrival and leaving dates per employee.

The difficulty is twofold:
1 - Where the period spans a Year End ie. Arrives 31 Oct 2011 and Leaves 15 Feb 2012...how to get the formulae to count the days in that range relative to each year (see below screenshots)

2 - There always will be a cell not yet completed if the employee is still here so the days column uses the today() function to calculate but how to include this into my formulae for totalling per year, I think it is causing a problem also since there is no date in cell C8 on first screenshot.

Any ideas anyone? Am hoping someone can quickly drop on that Eureka formula that will solve all my problems.....well my excel ones anyway ;)

Thanks,
Iain


****, I cannot seem to post the screenshots, let me see if I can type below (hope this comes out)

Example Form:
Employee NameArrivedLeftStayed
Mr ABC1-May-1115-Jul-1175
Mr ABC4-Aug-113-Oct-1160
Mr ABC6-Oct-1113-Feb-12130
Mr ABC16-Feb-12142
Mr ABC-
Mr ABC-
Mr ABC-
Mr ABC-
Mr ABC-
Mr ABC-
Mr ABC-

<TBODY>
</TBODY><COLGROUP><COL><COL><COL><COL></COLGROUP>


Formulae to calculate days (I know this is working wrong though
as noted in scenario 1)

1-Jan-071-Jan-081-Jan-091-Jan-101-Jan-111-Jan-12
31-Dec-0731-Dec-0831-Dec-0931-Dec-1031-Dec-1131-Dec-12
200720082009201020112012
Days per year 1170

<TBODY>
</TBODY><COLGROUP><COL><COL><COL span=2><COL><COL><COL></COLGROUP>



Actual Formula:
=SUMIFS($D$5:$D$119,$C$5:$C$119,"<="&K$3,$B$5:$B$119,">="&K$2)

<TBODY>
</TBODY><COLGROUP><COL></COLGROUP>

where D5:D119 = No of Days column
B5:B119 = Arrival Dates and K3 is 31st Dec each year
C5:C119 = Arrival Dates and K3 is 31st Dec each year


Any ideas? Am totally stuck :confused:
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Maybe something like this

Assuming K4 = 2007; L4=2008; M4=2009; N4=2010; O4=2011;P4=2012

Array-formula in K5
=SUM(IF(YEAR($B$5:$B$200)=K$4,IF($C$5:$C$200="",TODAY(),IF(YEAR($C$5:$C$200)>K$4,DATE(K$4,12,31),$C$5:$C$200))-$B$5:$B$200))

confirmed with Ctrl+Shift+Enter
(hold down both Ctrl and Shift keys and hit Enter)

copy across till P5

M.
 
Upvote 0
oops

The formula above has a flaw. It doesn't work if someone arrived on a previous year and still has not left.

M.
 
Upvote 0
Wow that's complicated and I tried it. It does work for year 2011 but not for 2012 as it does not seem to count the days from 1st Jan to 13th Feb but only from 16th Feb.

I think this is because it only counts if the Arrival date is in the same year so would need to amend that somehow. Getting close though but need to somehow get the earlier dates in? Any idea? Apologies if this one took a while but it is certainly very much appreciated

Iain
 
Upvote 0
Ah I see you beat me to the reply, sorry I hadnt refreshed my screen, I will try to see if I can include that somehow...
Iain
 
Upvote 0
Hi
This works across different years. Column D gives days including the start date. Came across Column F formulas in a search ages ago but forget who wrore it.


Excel Workbook
BCDEF
701/05/201115/07/201244263 Weeks 1 Days
801/05/201216/07/20127711 Weeks 0 Days
Sheet1
 
Upvote 0
That last one though does not sum the total days in a specific year, is simply number of dates in a range? Marcelo had it but for the opening date not being in the same year?

Have been tearing my hair out all morning on this?

I could probably add in hidden columns for each year and do an if formulae along the lines you mention above then total down the way but am trying not to do that and just incorporate it into 1 formula as I will have many tabs for different people and want to copy that cell accross once done :)

A rework of Marcelo's would be best if it is possible but it is above my brain power unfortunately ;(
 
Upvote 0
Any more thoughts anyone? Any other users know what I can do?

Thanks,
Iain

New version - ugly array formula (maybe someone has a better solution, but i think this works)

Assuming 2007 to 2012 in K4:P4

K5
=SUM(IF($B$5:$B$200<>"",IF(YEAR($B$5:$B$200)=K$4,IF($C$5:$C$200="",IF(K$4=YEAR(TODAY()),TODAY(),DATE(K$4,12,31)),IF(YEAR($C$5:$C$200)>K$4,DATE(K$4,12,31),$C$5:$C$200))-$B$5:$B$200,IF(K$4>YEAR($B$5:$B$200),IF($C$5:$C$200="",IF(K$4=YEAR(TODAY()),TODAY()-DATE(K4,1,1),365),IF(K$4=YEAR($C$5:$C$200),$C$5:$C$200-DATE(K$4,1,1)))))))

Ctrl+Shift+Enter

copy across till P5

M.
 
Upvote 0
New version - ugly array formula (maybe someone has a better solution, but i think this works)

Assuming 2007 to 2012 in K4:P4

K5
=SUM(IF($B$5:$B$200<>"",IF(YEAR($B$5:$B$200)=K$4,IF($C$5:$C$200="",IF(K$4=YEAR(TODAY()),TODAY(),DATE(K$4,12,31)),IF(YEAR($C$5:$C$200)>K$4,DATE(K$4,12,31),$C$5:$C$200))-$B$5:$B$200,IF(K$4>YEAR($B$5:$B$200),IF($C$5:$C$200="",IF(K$4=YEAR(TODAY()),TODAY()-DATE(K4,1,1),365),IF(K$4=YEAR($C$5:$C$200),$C$5:$C$200-DATE(K$4,1,1)))))))

Ctrl+Shift+Enter

copy across till P5

M.

WOW!!!! You are a genius Marcelo. If it works I dont mind if no other answer. Am home now but will try first thing on Monday, this is great, thank you...
 
Upvote 0

Forum statistics

Threads
1,217,371
Messages
6,136,180
Members
449,996
Latest member
duraichandra

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