Excel - Convert a range of text to dates in a formula - excel

The two columns in my data referred to in this formula are "Carrier" and the other column is "OriginalEffectiveDate". The second column consist of a range of dates over a two year span. I need to show a like count of carriers for both years.
So if the range of dates is Jan 1, 2014 to July 12, 2015 then I only want to count the carriers in 2014 up to July 12, 2014. So in other words; if I counted all of 2014 compared to just a portion of 2015 then my numbers would be off.
The results would be something like:
2014 = 343 (Jan 1 - July 12, 2014)
2015 = 375 (Jan 1 - July 12, 2015)
When I set the file up originally the data I was using was static and the dates were numeric fields. When I took the same file and made the connection directly to the database the dates are now coming in as text and I cant get the same formula to work.
Thanks in advance for your help.
=COUNTIFS(tbl_Group[Carrier],A5,tbl_Group[OriginalEffectiveDate],"<="&EDATE(MAX(tbl_Group[OriginalEffectiveDate]),-12))
Photo:

Can you add a calculated column to your table?
If so, try this: add column called CalculatedDate with formula =DATEVALUE([#OriginalEffectiveDate])
Your CountIfS formula becomes
=COUNTIFS(tbl_Group[Carrier],A10,tbl_Group[CalculatedDate],"<="&EDATE(MAX(tbl_Group[CalculatedDate]),-12))
Note: DATEVALUE will make assumptions about potentially ambiguous dates, in my case yyyy-mm-dd based on my regional settings.
The reason COUNTIFS can't work without a calculated column is that the criteria_range parameters must be a direct range, and tbl_Group[OriginalEffectiveDate] are strings, not dates.
An alternative formula that doesn't require a calculated column is
=SUMPRODUCT(
(tbl_Group[Carrier]=A12) *
(DATEVALUE(tbl_Group[OriginalEffectiveDate]) <=
MAX(EDATE(DATEVALUE(tbl_Group[OriginalEffectiveDate]),-12))
)
)

Related

Excel (IF) conditions with dates and changing status based on future dates

I have a question on excel, trying to use the below formula, if you can insert it in cell B4 and it will be referencing dates from column C. When testing this for date range 01-May-2022 till 30-Aug-2022, it displays a few FALSES, I am trying to fill these statuses without generating any issues with code, so it works flawlessly. At this stage the more I try to tweak it, the more it breaks.
The status I am requiring is:
If Today() is 31+ days before Column C date range, then "Not Due"
If Today() is anywhere between 1 and 30 before column C date range then "Due Soon"
If Today() = column C date, then "Due"
If Today() is greater than column C date then "Overdue"
Can anyone please suggest a fix for date ranges 01-May-2022 till 30-Aug-2022, appreciate it! False is observed for 26 June 2022, 26 July 2022, 27 July 2022, and 08 April 2023.
There is another False I have observed which appeared sometime around June 2023 for this formula, not sure if it is an issue with Excel?
Thank you.
Formula
=IF($C4="Not Required","Not Required",IF(ISNUMBER(VALUE(LEFT($C4,1))),IF(TODAY()>$C4,"Overdue",IF(AND(TODAY()<$C4,TODAY()>($C4-30)),"Due Soon",IF(TODAY()<($C4-31),"Not Due")))))
Something like this should work for you:
=IF($C4="Not Required",$C4,IF(ISNUMBER($C4),CHOOSE(MATCH($C4-TODAY(),{-99999,0,1,31}),"Overdue","Due","Due Soon","Not Due"),"Not Due"))

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

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.

How to convert a month number (i.e. "12") into month name in Excel?

I've got data in a spreadsheet that's formatted YYYYMM and I need to convert it to Month Year format (i.e. 201406 -> June 2014)
I'm using RIGHT() and LEFT() to pull the corresponding bits from the initial data cells, but I can't figure out how to turn the month number into a month name (i.e. 06 -> June, 01 -> January, etc.)
I've tried TEXT(RIGHT(B2,2),"mmmm") which only returns January regardless of the number inputted.
Ideally this should be easy, so, any thoughts? Thanks.
You can use DATE([Year],[Month],[Day]) passing any values for year and day. Just note that this will make the actual value of the cell different to 12 though.
Excel will be reading 12 as a date which will be 12 days after 00/01/1900 (this is 0 as a date) returning 12/01/1900 which is in January.
TEXT(DATE(1,B2,1),"mmmm")
To make 201406 -> June 2014, The Date() formula would do pretty good job indeed. This is the whole formula that would make the transition:
=TEXT(DATE(LEFT(A1,4),RIGHT(A1,2),1),"MMMM YYYY")
Or something hardcoded as this can work:
=CHOOSE(B1,"January","February","March","April","May","June","July")
Another way is to add "01" to the end of your number so you can format it to look like a date, and then return the month from it.
=Text($A$1 & "01","####-##-##") will return 2014-06-01.
=TEXT("2014-06-01","mmmm yyyy") will return June 2014.
So....
=TEXT(TEXT($A$1 & "01","####-##-##"),"mmmm yyyy") returns June 2014.

Formula to convert quarter-year to MM/DD/YYYY in Excel

I want to convert a column of dates in QTR/YR format to MM/DD/YYYY format, using the first day of the quarter (the first days of the four quarters are Jan. 1, April 1, July 1 and Oct. 1.) How can I go about doing this?
Example:
4Q14 should become 10/01/2014
3Q14 should become 7/01/2014
2Q14 should become 4/01/2014
and so forth.
Try this:
=Date(Right(A1,2)+2000,CHOOSE(Left(A1,1),1,4,7,10),1)
If cell A1 contains the text, then
=DATE(2000+RIGHT($A$1,2),-2+3*LEFT($A$1,1),1)
is one way. That will yield a number that you can format as a date, using the format of your choice.

Excel will not read date

I've tried a million things to get Excel to read a date that is being pulled by this formula:
=(LEFT(VLOOKUP(C7,'Input Engagement Status'!C:M,9,FALSE),11))
I use LEFT because the cell I'm referencing is storing two dates simultaneously. The output is "mmm dd yyyy".
I have tried text to columns, but the formula is being pulled apart rather than the date that it reads for.
I have tried custom formatting to create a new date format for "mmm dd yyyy". I have changed from general, to numbers, to text, and I am out of solutions at this point. Any help would be greatly appreciated.
A way to illustrate the differences is with a date on the worksheet. Excel treats dates as 1 for every day past Dec 31, 1899. Today happens to be 42,192 (or 42192 as Excel sees it).
If you put =TODAY() in a cell (e.g. A1) and use =RIGHT(A1, 2), the A1 cell probably shows 07/07/2015 but the underlying value is 42192 so the RIGHT(A1, 2) is going to return 92. Format the cell so it displays Tuesday, July 7, 2015 and RIGHT(A1, 2) is still going to return 92.
If you have two dates in the same cell separted by a space or other delimiter as a text string then you should be able to pull the first 11 characters from the string value and convert it back to a date with the DATEVALUE function.
Using this data in a single cell (A1):
Jul 07 2015 Jul 15 2015
Use the SUBSTITUTE function to insert a comma so that DATEVALUE will resolve the date correctly.
=DATEVALUE(SUBSTITUTE(LEFT(A1, 11), " 20", ", 20"))
=DATEVALUE(SUBSTITUTE(RIGHT(A1, 11), " 20", ", 20"))
Format the result as a date. The above will return 42,192 and 42,200 (the number of days since Dec 31, 1899). Format as a date to get something like 07/07/2015 and 07/15/2015.
You should be able to transcribe your VLOOKUP function into that simple example.

Resources