Count days from date range

%3CLINGO-SUB%20id%3D%22lingo-sub-2544501%22%20slang%3D%22en-US%22%3ECount%20days%20from%20date%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2544501%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20list%20of%20time%20off%20requests%20that%20are%20listed%20as%20date%20ranges%20(ie.%206%2F7%2F21%20-%206%2F10%2F21%20)%20and%20I%20need%20to%20make%20a%20count%20of%20how%20many%20days%20off%20are%20requested%20for%20each%20date%2C%20ideally%20without%20having%20to%20manually%20input%20each%20date%20between%20the%20date%20ranges.%20So%20i%20want%20to%20be%20able%20to%20input%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CSPAN%3E6%2F7%2F21%20-%206%2F10%2F21%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E6%2F8%2F21%20-%206%2F8%2F21%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E6%2F8%2F21%20-%206%2F9%2F21%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Eand%20be%20able%20to%20get%20a%20list%3C%2FP%3E%3CP%3E6%2F7%2F21%20-%201%3CBR%20%2F%3E6%2F8%2F21%20-%203%3CBR%20%2F%3E6%2F9%2F21%20-%202%3CBR%20%2F%3E6%2F10%2F21%201%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2544501%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2544646%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20days%20from%20date%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2544646%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1102664%22%20target%3D%22_blank%22%3E%40Maride2225%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhy%201%20for%206%2F7%2F21%20-%206%2F10%2F21%20%3F%3C%2FP%3E%0A%3CP%3EWhy%203%20for%206%2F8%2F21%20-%206%2F8%2F21%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2544667%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20days%20from%20date%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2544667%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1102664%22%20target%3D%22_blank%22%3E%40Maride2225%3C%2FA%3E%26nbsp%3B%20See%20the%20attached.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mtarler_0-1626211156117.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F295600i854F76F0A705489F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22mtarler_0-1626211156117.png%22%20alt%3D%22mtarler_0-1626211156117.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Efirst%20I%20assumed%20that%20the%20dates%20may%20be%20entered%20just%20as%20you%20said%20(or%20as%20a%20single%20date)%3C%2FP%3E%3CP%3Esecond%20I%20assumed%20you%20have%20the%20latest%20version%20of%20Excel%20(365%20subscription)%3C%2FP%3E%3CP%3ESo%20first%20I%20converted%20that%20mix%20of%20dates%20and%20text%20to%202%20columns%20for%20start%20date%20and%20end%20date%20(columns%20C%20and%20D)%3C%2FP%3E%3CP%3Ethen%20I%20created%20a%20list%20of%20all%20possible%20dates%20from%20first%20to%20last%20and%20the%20corresponding%20count%20that%20particular%20date%20is%20found%20in%20any%20of%20those%20ranges%20(columns%20F%20and%20G)%3C%2FP%3E%3CP%3Ethen%20I%20filtered%20that%20table%20of%20all%20dates%20to%20show%20only%20the%20dates%20that%20have%20a%20count%20%26gt%3B%200%26nbsp%3B%20(columns%20I%20and%20J)%3C%2FP%3E%3CP%3ETHEN%20I%20converted%20all%20of%20those%20helper%20columns%20into%20a%20single%20massive%20LET%20statement%20in%20M2%20(i.e.%20you%20could%20delete%20all%20the%20other%20columns%20but%20I%20left%20them%20there%20to%20show%20the%20process%20I%20did)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2544693%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20days%20from%20date%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2544693%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1102664%22%20target%3D%22_blank%22%3E%40Maride2225%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20only%20works%20in%20Excel%20365.%26nbsp%3B%20Even%20then%2C%20it%20is%20something%20of%20a%20nightmare!%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20h%2C%20SEARCH(%22-%22%2C%20requestedDates)%2C%0A%20%20%20start%2C%20%20--MID(requestedDates%2C%201%2C%20h-2)%2C%0A%20%20%20end%2C%20%20%20%20--MID(requestedDates%2C%20h%2B2%2C%209)%2C%0A%20%20%20minStart%2C%20MIN(start)%2C%0A%20%20%20maxEnd%2C%20%20%20MAX(end)%2C%0A%20%20%20calendar%2C%20SEQUENCE(1%2C%20maxEnd-minStart%2B1%2C%20minStart%20)%2C%0A%20%20%20request%2C%20(calendar%26gt%3B%3Dstart)*(calendar%26lt%3B%3Dend)%2C%0A%20%20%20count%2C%20%20%20%20MMULT(TRANSPOSE(request)%2C%20SIGN(start))%2C%0A%20%20%20IF(%7B1%2C0%7D%2C%20TRANSPOSE(calendar)%2C%20count)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20formula%20extracts%20the%20two%20parts%20of%20the%20date%20range%20and%20coerces%20each%20to%20become%20a%20date%20(must%20be%20the%20correct%20locale%20for%20the%20machine).%26nbsp%3B%20The%20'calendar'%20is%20the%20sequence%20of%20dates%20inclusive%20of%20the%20first%20and%20last%20requested%20date.%26nbsp%3B%20Each%20date%20is%20tested%20against%20each%20leave%20request.%26nbsp%3B%20MMULT%20is%20used%20to%20sum%20over%20the%20requests.%3C%2FP%3E%3CP%3ENote%3A%20%3CEM%3EI%20had%20to%20rewrite%20the%20dates%20in%20a%20non-US%20format%20for%20the%20formula%20to%20work.%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Visitor

I have a list of time off requests that are listed as date ranges (ie. 6/7/21 - 6/10/21 ) and I need to make a count of how many days off are requested for each date, ideally without having to manually input each date between the date ranges. So i want to be able to input


6/7/21 - 6/10/21
6/8/21 - 6/8/21
6/8/21 - 6/9/21

and be able to get a list

6/7/21 - 1
6/8/21 - 3
6/9/21 - 2
6/10/21 1

3 Replies

@Maride2225 

Why 1 for 6/7/21 - 6/10/21 ?

Why 3 for 6/8/21 - 6/8/21 ?

@Maride2225  See the attached.

mtarler_0-1626211156117.png

first I assumed that the dates may be entered just as you said (or as a single date)

second I assumed you have the latest version of Excel (365 subscription)

So first I converted that mix of dates and text to 2 columns for start date and end date (columns C and D)

then I created a list of all possible dates from first to last and the corresponding count that particular date is found in any of those ranges (columns F and G)

then I filtered that table of all dates to show only the dates that have a count > 0  (columns I and J)

THEN I converted all of those helper columns into a single massive LET statement in M2 (i.e. you could delete all the other columns but I left them there to show the process I did)

@Maride2225 

This only works in Excel 365.  Even then, it is something of a nightmare!

= LET(
   h, SEARCH("-", requestedDates),
   start,  --MID(requestedDates, 1, h-2),
   end,    --MID(requestedDates, h+2, 9),
   minStart, MIN(start),
   maxEnd,   MAX(end),
   calendar, SEQUENCE(1, maxEnd-minStart+1, minStart ),
   request, (calendar>=start)*(calendar<=end),
   count,    MMULT(TRANSPOSE(request), SIGN(start)),
   IF({1,0}, TRANSPOSE(calendar), count) )

The formula extracts the two parts of the date range and coerces each to become a date (must be the correct locale for the machine).  The 'calendar' is the sequence of dates inclusive of the first and last requested date.  Each date is tested against each leave request.  MMULT is used to sum over the requests.

Note: I had to rewrite the dates in a non-US format for the formula to work.