Excel - count days in each month between two dates (both dates available) - excel

I have found the solution thought it would be good to share:
so the formula should be :
=((MAX(CT$6-$N8,0)-MAX(EOMONTH(CT$6,-1)-$N8,0))-(MAX(CT$6-$O8,0)-MAX(EOMONTH(CT$6,-1)-$O8,0))+(EOMONTH(CT$6,0)=EOMONTH($N8,0)))*1
:)
I am trying to write an excel formula which can be dragged across a row of cells to give the number of days in each month between two specified dates. E.g:
I tried using a if with sum product formula from the same website but for some reason it is not recognising the days of last month. was wondering if someone could help explain what this formula does and how to correct it.
=IFERROR(IF(AND(CS$6>=$M9,CS$6<=$N9),SUMPRODUCT(--(MONTH(ROW(INDIRECT($M9&":"&IF($N9="",TODAY(),$N9))))=MONTH(CS$6))),),"")

SECOND REVISION (R2)
Updated workbook link to capture fixed column headings
Eqn / formula also includes static view
Depending upon years spanned, R2 represents a less favourable outcome re space (will require more columns). In this case, number of additional columns required to match stacked view ~100 (!!).
FIRST REVISION (R1) etc. based upon #Charlotte.Sarah.Smith feedback
Days in each month were 1 day less than they should have been - this has been corrected (in both screenshot, linked sheet, and relevant eqns)
Also showcase a couple of sample illustrations/visual representations which may/not be of interest (included within linked sheet too)
Suppose we wanted to expand upon #Will's solution by stacking the dates by year, so that column headings can vary according to different start dates (as opposed to the very first start date that happens to appear)...
For instance, if the next row included the date range 'start = 10/02/16' through 'end = 15/03/19' - you'll appreciate that the number of columns spanning Jan-Dec ('16), Jan-Dec ('17),... up to (and incl.) the range in the first row (Jan '21 - Mar '23) becomes unwieldy.
By using a data table (see here) you can produce a 'stacked' view of the number of days per month regardless of the year (!) - see screenshot below and link to this [updated/corrected] worksheet.
R2 screenshot:
REVISION
See validation/reconciliation column at end
*Visual representations - could be useful for assessing trends etc.
Fun in 3D too!
1] Red font: first row that defines the construct of the data table: enter date range in the format '10/02/2021-15/08/2023'
Cell E3 eqn (drag to right):
=IFERROR(IF($A3>EDATE(E$2,1),0,MAX(,IFERROR(IF(MIN($B3,MIN(EDATE(E$2,1),$B3))=E$2-1,0,MIN($B3,MIN(EDATE(E$2,1),$B3))),"")-MAX($A3,E$2))),0)
(Similar to what we've seen previously)
2] Table below red font: enter any start date (as a regular date, e.g. dd/mm/yyyy) < end date (likewise, regular date) in columns A, B as desired/req.
Data Table
3] Data Table (column data): enter the following in cell c4 (drag down as req.)
=TEXT(A4,"dd/mm/yyyy")&"-"&TEXT(B4,"dd/mm/yyyy")
4] Data Table (highlight cells c3:d42, insert data table, select blank/empty cell for 'row input' and c2 for 'column input')
The data table should 'come to life' (calculate sheet, shift + F9) otherwise.
FilterXML
5] Split result by delimiter '|' using FilterXML as follows (cell E4, only drag down, not to right):
=IFERROR(TRANSPOSE(FILTERXML("<AllText><Num>"&SUBSTITUTE(LEFT(MID(D4,2,LEN(D4)-1),LEN(MID(D4,2,LEN(D4)-1))-1),"|","</Num><Num>")&"</Num></AllText>","//Num")),"")
VALIDATION
Note the check column: date difference = sum of days in table (default cell colour is otherwise RED):
REVISION 2
Here is the formula for a static version of above (i.e. no stacking by year, instead, each date in column headers are distinct re calcs) - it was already available in row with red font(!!)
=IFERROR(IF($A3>EDATE(C$2,1),0,MAX(,IFERROR(IF(MIN($B3,MIN(EDATE(C$2,1),$B3))=C$2-1,0,MIN($B3,MIN(EDATE(C$2,1),$B3))),"")-MAX($A3,C$2))),0)
Viola!

One potential solution would be to compare dates using the MIN and MAX functions like this:
=IF(MIN($B2+1,D$1)-MAX($A2,C$1)<0,"",MIN($B2+1,D$1)-MAX($A2,C$1))
screenshot
This solution uses month starting dates (e.g., Feb 1, 2021), but it could be adapted to work with month end dates instead (e.g., Feb 28, 2021).
The idea is that you take the later of the finish date or month end date minus the lesser of the start date or the month start date. For the first month and last months, this returns the number of days within that range inclusive of the first and last day. For all the months between the first and last months, it returns the number of days in the month.
The +1 on the minimum of the end dates seems a little counterintuitive, but it's necessary to include the first and last day in the count. Without it, you'd get 14 days in March 2022 instead of 15.
The "if less than zero" function makes it return a blank (or zero if you'd prefer) for any month outside the dat range.
This solution does not summarize by month (e.g., 19 days for Feb 2021 plus 28 days for 2022 to get 47 total days in February), but that's consistent with the sample you provided. The comments also indicate that you want to consider the years as well.

Related

If date is older than 6 months and value is X, then output this

I have two columns in excel, one with a date and one with a rating 'low, medium, high'.
I'm trying to write a formula to put in a third column that checks:
If A2 = Low and B2 (date) is older than 12 months from today(), output Overdue
If A2 = Medium and B2 (date) is older than 6 months from today(), output Overdue
If A2 = High and B2 (date) is older than 3 months from today(), output Overdue
If these parameters aren't met, output "Current".
This is what I have so far but I'm well aware its not right :)
Could someone please point me in the right direction?
Thanks,
=IF(AND(A2="Low",LOOKUP(DATEDIF(B2,TODAY(),"m"),{0,3,6,12},{"Current", "Current" "Current","Overdue"}),(A2="Medium",LOOKUP(DATEDIF(B2,TODAY(),"m"),{0,3,6,12},{"Current","Current","Overdue","Overdue"}),(A2="High",LOOKUP(DATEDIF(B2,TODAY(),"m"),{0,3,6,12},{"Current","Overdue","Overdue","Overdue"})
If you can use the excel 365 then I’d suggest creating an excel lambda function:
=LAMBDA(level, date, LET(months, IFS(level="Low",12,level="Medium",6,level="High",3,TRUE,0), IF(date < EDATE(Today(), -months),"Overdue", "Current")))
so to break it down, this is a custom function that expects 2 parameters :
level is the value/reference that has low/medium/high. this is used to determine the number of months for the threshold - 12/6/3 respectively and 0 for anything else though you could change that as needed.
date is the date to check if its beyond the threshold. this is compared against today minus the number of months calculated from the level. if this is before that date then this function will return “Overdue”. otherwise “Current”.
You would create a workbook level named reference with this function as the value.
Here I named it IsCurrent. Then you just use that function where you want the output. e.g.
What I would suggest is to "outsource" the settings for the overdue months.
This is a good habit, as everyone looking at the table can see those settings and propably adjust them - without going into the formula.
And it is possible to use these settings in another formula :-)
If you use Excel 365 you can make the formula more readable/understandable with the LET-Formula.
=LET( OverdueMonthsForRating, IFNA(INDEX(configOverdue[Overdue months],MATCH([#Rating],configOverdue[Rating],0)),0), OverdueDate,IF(OverdueMonthsForRating>0, EDATE([#Date],OverdueMonthsForRating),TODAY()), IF(OverdueDate<TODAY(),"overdue","current") )
OverdueMonthsForRating is using a classic INDEX/MATCH to retrieve the number of months according to the Rating. In case Rating is not found 0 is returned
OverdueDate calculates - using EDATE - the overdue date based on the ratings date and OverdueMonthsForRating. In case Rating is not found TODAY is returned
Finally this date is evaluated against TODAY and the status is returned.
Classic Excel formula w/o LET:
=IF(EDATE([#Date],IFNA(INDEX(configOverdue[Overdue months],MATCH([#Rating],configOverdue[Rating],0)),TODAY()))<TODAY(),"overdue","current")

How to filter out partial match in an Excel row?

I have an Excel sheet with dates in the rows. A given month should be used only once in a row. How can I filter out, if there are two dates in the same row from the same month?
For example I have the following array, and I would like to have as a result, that there is a match in this row (2012-03).
2012-03-04 2012-02-05 2012-04-06 2012-03-07 2012-10-08 2012-11-09 2012-12-10
I have tried to combine aggregate and match functions, but I cannot find out how to do it properly.
One of my codes, of course it gave an error:
=aggregate(9,6,(MATCH("*"&LEFT(A8,7)&"*","*"&LEFT(b8,7)&"*",0), MATCH("*"&LEFT(b8,7)&"*","*"&LEFT(c8,7)&"*",0)))
Ok, now I have tried another way, and I could get a solution, but with a code which is like a km long...I have first created a new dataset, cutting down the days by using: =""&LEFT(A8,7)&""
Then I have compared all the cells in a given row of my new dataset. Could someone help me how to shorten the exact( ) parts? The aim is to compare all.
=if((or(exact(A2, B2), exact(A2,C2),exact(A2,D2),exact(A2,E2),exact(A2,F2),exact(A2,G2),exact(A2,H2),exact(A2,I2),exact(A2,J2),exact(A2,K2),exact(A2,L2),exact(A2,M2),exact(A2,N2),exact(A2,O2),exact(A2,P2),exact(A2,Q2),exact(A2,R2),exact(B2,C2),exact(B2,D2),exact(B2,E2),exact(B2,F2),exact(B2,G2),exact(B2,H2),exact(B2,I2),exact(B2,J2),exact(B2,K2),exact(B2,L2),exact(B2,M2),exact(B2,N2),exact(B2,O2),exact(B2,P2),exact(B2,Q2),exact(B2,R2),exact(C2,D2),exact(C2,E2),exact(C2,F2),exact(C2,G2),exact(C2,H2),exact(C2,I2),exact(C2,J2),exact(C2,K2),exact(C2,K2),exact(C2,L2),exact(C2,M2),exact(C2,N2),exact(C2,O2),exact(C2,P2),exact(C2,Q2),exact(C2,R2),exact(D2,E2),exact(D2,F2),exact(D2,G2),exact(D2,H2),exact(D2,I2),exact(D2,J2),exact(D2,K2),exact(D2,L2),exact(D2,M2),exact(D2,N2),exact(D2,O2),exact(D2,P2),exact(D2,Q2),exact(D2,R2),exact(E2,F2),exact(E2,G2),exact(E2,H2),exact(E2,I2),exact(E2,J2),exact(E2,K2),exact(E2,L2),exact(E2,M2),exact(E2,N2),exact(E2,O2),exact(E2,P2),exact(E2,Q2),exact(E2,R2),exact(F2,G2),exact(F2,H2),exact(F2,I2),exact(F2,J2),exact(F2,K2),exact(F2,L2),exact(F2,M2),exact(F2,N2),exact(F2,O2),exact(F2,P2),exact(F2,Q2),exact(F2,R2),exact(G2,H2),exact(G2,I2),exact(G2,J2),exact(G2,K2),exact(G2,L2),exact(G2,M2),exact(G2,N2),exact(G2,O2),exact(G2,P2),exact(G2,Q2),exact(G2,R2),exact(H2,I2),exact(H2,J2),exact(H2,K2),exact(H2,L2),exact(H2,M2),exact(H2,N2),exact(H2,O2),exact(H2,P2),exact(H2,Q2),exact(H2,R2),exact(I2,J2),exact(I2,K2),exact(I2,L2),exact(I2,M2),exact(I2,N2),exact(I2,O2),exact(I2,P2),exact(I2,Q2),exact(I2,R2),exact(J2,K2),exact(J2,L2),exact(J2,M2),exact(J2,N2),exact(J2,O2),exact(J2,P2),exact(J2,Q2),exact(J2,R2),exact(K2,L2),exact(K2,M2),exact(K2,N2),exact(K2,O2),exact(K2,P2),exact(K2,Q2),exact(K2,R2),exact(L2,M2),exact(L2,N2),exact(L2,O2),exact(L2,P2),exact(L2,Q2),exact(L2,R2),exact(M2,N2),exact(M2,O2),exact(M2,P2),exact(M2,Q2),exact(M2,R2),exact(N2,O2),exact(N2,P2),exact(N2,Q2),exact(N2,R2),exact(O2,P2),exact(O2,Q2),exact(O2,R2),exact(P2,Q2),exact(P2,R2),exact(Q2,R2))),"same month","ok")
Thank you in advance.
I am not sure if there is a better way, but this is how I'd tackle the problem based on my Excel knowledge:
Add data of dates above in cells A1-G1
On row below date add formulas for dates: A2=DATE(A1) ..... G2=DATE(G1)
At the end of the original row of dates add the numbers 1 thru 12:
using formula cell H1=1, I1=H1+1 ..... S1=R1+1
After the months on row 2:H2=COUNTIF($A2:$G2,H1) ..... S2=COUNTIF($A2:$G2,S1)Counting frequency for each of the 12 months
T2=MAX(H2:S2)
Then select on cell T2being more than 1.
Here it is as a Google sheet (you can download it and open in Excel if you want)
Maybe this will help. Assume that the range of dates is in $A$1:$G$1. Also assume that the entries are numerical dates; if they are instead text you can handle this by using the DATEVALUE function. Then we can get the years and months of the range with:
{=YEAR($A$1:$G$1)}
{=MONTH($A$1:$G$1))
This and all other formulas must be entered as array formulas (CrtlShiftEnter).
We next convert back to a date, but use 1 for the day, so that all dates get shifted to the first day of the month (this means that any dates from the same month are shifted to the same date):
{=DATE(YEARS,MONTHS,1)}
We can produce an NxN comparison of the shifted dates by:
{=TRANSPOSE(SHIFTED_DATES)=SHIFTED_DATES}
We can count the number of True's in this array by:
{=SUM(--(ARRAY))}
If there we no dates from the same month we'd expect this to sum to N because this method compare each date to itself as well as the other dates. The causes the N elements on the main diagonal of this array to be True. If any dates are in the same month off-diagonal elements will also be True. So to detect if there are dates from the same month we make the comparison:
{=SUM(--(ARRAY)) > N}
or more generally:
{=SUM(--(ARRAY)) > COUNT($A$1:$G$1)}
Rolling all of these up into one formula:
=IF(SUM(--(TRANSPOSE(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1))=DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)))>COUNT(DATE(YEAR($A$1:$G$1),MONTH($A$1:$G$1),1)),"same month","ok")
If your dates are in a range other than $A$1:$G$1 then make the appropriate substitutions.
Hope that helps.

Finding the last occupied cell using a formulae

This formulae "works", but it seems a bit long winded. Can anyone suggest an "easier" formulae. It returns the value in the 5th Column to a date in the 1st column which is called from a separate (and discrete) worksheet. If there is no data in the 5th column (because we haven't reached or passed that date), then the latest available data is called ($A$20, is the "calling date, on a current worksheet):-
IF(VLOOKUP($A$20,'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5)="",VLOOKUP(HLOOKUP(A20,'[FTSE100.xlsx]Meteor Step
Down Plans'!$A$18:$A$2628,MATCH(TRUE,INDEX(ISBLANK('[FTSE100.xlsx]Meteor
Step Down Plans'!$E$18:$E$2828),0,0),0)-1),'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5),VLOOKUP($A$20,'[FTSE100.xlsx]Meteor Step Down
Plans'!$A$18:$E$2828,5))
The formula is in a different workbook to the data. The formula is used to determine the last value in an array, the first column of which is a date range (01/01/2000 to 31/12/2027....say) The required data is in column 5. Entries may be up to date (i.e. the last entry was made today, therefore it will pickup todays value. The last entry may have been several days (weeks) ago, therefore it will pick up the last value in the designated column (column 5). I don't see why it can't go into a named range, as the array size is fixed. Does that help?
Thanks Ron, nearly there. That works beautifully for "missing" dates in the array. i.e. when Saturday and Sunday dates are missing, it finds the value (in column 5) of the previous Friday. However (and there is usually a "however"), if $A$20 is a date in advance of the date of the last data in the array i.e. column 5 is blank at that date, your formulae returns 0 (zero), instead of the data as at the last date that data has been entered. i.e. enter 02/04/2018 and your formulae returns 0, not the data at the last date available 28/02/2018. Is that a little more clear?? (Thank you anyway, for spending the time - I'm still trying to work out how your formulae works as it does. Is the "/" significant (other than being a "divide by" symbol, if so it's something I've never come across before? Regards...........Mike. P.S. The dates in the array (Column 1) are all in from 2016 to 2027 (excluding weekend and bank holidays), and are arranged in ascending order i.e. from 01/01/2016 to 31/12/2027
Ron - Sorry mate, buy I can't see a "second" formulae???
If I understand what you want to do correctly, (and that is hard to do since you give NO examples of your data, actual output or desired output), try:
=LOOKUP(2,1/((myDate>=A:A)*(LEN(A:A)>0)),E:E)
If it is the case that you have dates in column A and no entries in Column E, then you might have to do something like:
=LOOKUP(2,1/((myDate>=A:A)*(LEN(A:A)>0)*(LEN(E:E)>0)),E:E)
Of course, you will have to modify the cell references and named range to refer to the proper workbooks and cell.
Possibly something like:
=LOOKUP(2,1/(($A$20>='[FTSE100.xlsx]Meteor Step Down Plans'!$A$18:$E$2828)*(LEN('[FTSE100.xlsx]Meteor Step Down Plans'!$A$18:$E$2828)>0)),'[FTSE100.xlsx]Meteor Step Down Plans'!$E$18:$E$2828)
This should return the item from Column E that is either at or above the same row as myDate in Column A. If myDate does not exist in column A, it will match the nearest earlier date in Column A and return from that row in Column E.
In the second version of the formula, it also checks that there is an entry in Column E matching the column A date, and, if not, it will look above.

Excel #Value! error - but correct formula

I have an Excel 2010 workbook with this formula:
=EOMONTH("01"&TEXT(B7,"MMM")&IF(MONTH(CMVAR)<4,TEXT(YEAR(CMVAR)-1,"YYYY"),TEXT(YEAR(CMVAR),"YYYY")),0)
It resolves when you are in the cell and press Enter, however when the workbook first opens or is refreshed, the result is #VALUE!. Here are the components:
B7 =IF(OR(MONTH(CMVAR)>6,MONTH(CMVAR)<4),"Apr",IF(MONTH(CMVAR)=4,TEXT(EDATE(CMVAR,-3),"MMM"),IF(MONTH(CMVAR)=5,TEXT(EDATE(CMVAR,-3),"MMM"),TEXT(EDATE(CMVAR,-3),"MMM"))))
which equates to Apr.
CMVAR 31/03/2015
The formula is being used because in April, May, June (first three fiscal periods) we require comparison data to show in the 12-period grid from the previous financial year. From July onwards we will have comparable data from the current year and so the grid can start from April. Once the month has been determined I'm trying to work out what the date of the end of that period is, taking into account that Jan, Feb and Mar are actually periods 10, 11 and 12 of the fiscal year and so the year element of the formula will be the prior year if CMVAR shows the date to be in any of those months.
Is there a better way that avoids the error or a way to fix it?
It is not completely clear what result do you expect for different values of CMVAR, but looking at your formula, I suppose you want it to be:
You can calculate Result with the following formula:
=EOMONTH(CMVAR,-MAX(MOD(MONTH(CMVAR)-4,12),3))
If the picture above does not show your expected output, can you please prepare similar table?
EDIT:
To explain how the problem is solved, I have created additional columns with intermediate calculations:
column C is the month difference between CMVAR and expected result - the goal is to find a formula returning this number
column D calculates month of CMVAR
column E - function MOD returns the remainder after number is divided by divisor (12).
column E matches all values of C, except 0,1,2, so in column F function MAX replaces those values with 3
Your EOMONTH formula is going wrong because the TEXT part should be in the form TEXT(date,"YYYY"). YEAR(CMVAR) gives a number rather than a date.
You could use instead
=EOMONTH("01"&TEXT(B7,"MMM")&IF(MONTH(CMVAR)<4,TEXT(EDATE(CMVAR,-12),"YYYY"),TEXT(CMVAR"YYYY")),0)
or this may be easier than using the TEXT functions
=EOMONTH("01"&B7&IF(MONTH(CMVAR)<4,YEAR(CMVAR)-1,YEAR(CMVAR)),0)
Your B7 formula is OK but could be simplified to
=IF(OR(MONTH(CMVAR)>6,MONTH(CMVAR)<4),"Apr",TEXT(EDATE(CMVAR,-3),"MMM"))

Given a date range, count # of workdays per pay period the range falls in

I have a list of roughly 6500+ rows in Excel2007. Each row represents the time that a person was on disability leave with a start date and an end date. If there is no end date, then the end date is set to 12/31/9999. A sample of some values is below:
Workers Compensation 4/7/2009 12/31/9999
Workers Compensation 5/21/2009 12/31/9999
Short Term Disability 8/27/2009 10/7/2009
Short Term Disability 6/22/2009 7/15/2009
Short Term Disability 1/21/2009 10/4/2009
Short Term Disability 4/8/2009 6/14/2009
Short Term Disability 6/19/2009 10/5/2009
Short Term Disability 8/19/2009 12/31/9999
Short Term Disability 5/30/2009 6/18/2009
Short Term Disability 7/9/2009 7/20/2009
The first date is the date they went on leave; the second date is the date they returned from leave.
I am trying to break out each row so that I can get a count of the number of days per pay period that the person was on leave. We pay bi-weekly with the first pay of 2009 covering the period between 12/14/08 and 12/27/08 and incrementing bi-weekly thereafter (pay #2 covers 12/28/08 thru 1/10/09 etc).
So, as an example, I know that the first row of data covers pay periods 200909 thru the current pay period (we are currently on pay period 200924). I also know that periods 200910 thru 200924 should have 10 days as the calculated figure (since there are 10 workdays per pay), and that the count for pay period 200909 should be 2 (since there are 2 workdays in that payperiod that overlap with when the employee was on leave.
I'd like to use a formula to evaluate this, rather than writing code. Any ideas? Thanks in advance.
Pivot table method. Enter these formula
G1:12/26/2008
G2:=G1+14
and fill down to row 28. Then
A14: Date
A15: 1/21/2009
A16: =A15+1
B14: Count
B15: {=SUM(($B$1:$B$10<=A15)*(WEEKDAY(A15)<7)*(WEEKDAY(A15)>1)*($D$1:$D$10>=A15))}
C14: Week
C15: =INDEX($G$1:$G$28,MATCH(A15+13,$G$1:$G$28))
Fill A, B, and C formulas down to row 321 to stop on 11/23/09 (or farther if you want).
Select A14:C321 and create a pivot table. Put 'Week' in row area and 'Count' in the data area.
Enter the following formulas
G1:12/26/2008
G2:=G1+14
and fill down to row 28. Then
D1:=IF(C1=DATE(9999,12,31),TODAY(),C1)
E1:=NETWORKDAYS(B1,INDEX($G$1:$G$28,MATCH(B1+13,$G$1:$G$28)))
F1:=10-NETWORKDAYS(D1+1,INDEX($G$1:$G$28,MATCH(D1+14,$G$1:$G$28)))
and fill down as necessary. Then
H1:{=SUM(($B$1:$B$10<=G1-14)*($D$1:$D$10>G1))}
I1:{=SUM(($B$1:$B$10<G1)*($B$1:$B$10>=G1-14)*($E$1:$E$10))}
J1:{=SUM(($D$1:$D$10>G1-14)*($D$1:$D$10<=G1)*($F$1:$F$10))}
K1:=SUM(H1*10,I1,J1)
Note that formulas surrounded by brackets need to be array entered - do not enter the brackets, rather commit the formula with control+shift+enter instead of just enter.
Obviously you can combine a bunch of columns for brevity if you like.
Here, I am making a couple of assumptions:
The type of leave is under column A. The start and end dates are under columns B and C.
The rows start at row 1.
You are only concerned about pay periods starting December 14, 2008.
You are not taking bank/public holidays into account (although taking them into
account is not that big a deal).
The worker's leave includes the end date.
I used several cells to solve this problem:
In cell D1: =IF(C1=DATE(9999,12,31),TODAY(),C1)
In cell E1: =B1 - MOD(B1-DATE(2008,12,14),14) - 1
In cell F1: =D1 - MOD(D1-DATE(2008,12,14),14) - 1
In cell G1: =(F1-E1)/14 - 1
In cell H1: =(NETWORKDAYS(E1,B1) + NETWORKDAYS(F1,D1) + (G1 - 2) * 10)/ G1
Cell D1 determines whether the leave is ongoing. Cell G1 counts the number of pay periods between the start and end pay period. Cell H1 contains the answer you seek.
You can copy these cells for the other rows. Also, I would consider substituting TODAY() for 12/31/9999 for column C, if that's feasible.
UPDATED
I noticed that if no end date is specified, the value for the column corresponding with the pay period today's date belongs to should be 10. Also, I didn't ensure that for the first pay period the leave falls under, I should return the number of days the person is on leave for that period. Taking the above into account, as well as the clarifications provided, I came up with the following solution.
I make the same assumptions as above except that assumption 2 is replaced with the assumption that the rows start at row 2.
I defined the following names:
FirstPayPeriod: =DATE(2008, 12,14)
PayPeriodLength: =14
MaxDaysPerPeriod: =NETWORKDAYS(FirstPayPeriod, FirstPayPeriod + PayPeriodLength)
NoEndDate: =DATE(9999, 12, 31)
I defined the following cells and copied down the desired number of rows:
Cell D2: =IF(C2 = NoEndDate, FirstPayPeriod + PayPeriodLength * ROUNDUP((TODAY() - FirstPayPeriod)/PayPeriodLength, 0) - 1, C2)
Cell E2: =NETWORKDAYS(B2,D2)
I then defined the following cells for the top row:
Cell F1: =FirstPayPeriod
Cell G1: =F1 + PayPeriodLength
I then copied cell G1 across columns for as many pay periods I would like to represent. Of course, cell F1 and each subsequent cell to the right specify the start date of the pay period that the column represents.
I finally defined the following cell and copied to as many columns to the right as there are pay periods (EXCEPT FOR THE LAST PAY PERIOD - SEE BELOW), as well as copied down to as many rows as there is data:
Cell F2: =IF(OR(G$1 <= $B2, F$1 > $D2), 0, MIN($E2, NETWORKDAYS(F$1, G$1 - 1), NETWORKDAYS($B2, G$1), NETWORKDAYS(F$1, $D2)))
For the last pay period, I did the following. Assuming that column AD holds data for the last pay period:
Cell AD2: =IF(AC$1 > $D2, 0, MIN($E2, NETWORKDAYS(AD$1, AD$1 + PayPeriodLength - 1), NETWORKDAYS(AC$1, $D2)))
I then copied down as many rows as there is data.

Resources