Change a four digit number to a year in Excel - excel

I have a dataset that I'm working on. The dataset has a column with four-digit numbers. (1960, 1961,...2010)
I'm experimenting with the dataset in Power Query and I noticed that Power Query doesn't recognize the column as a year. Whenever I click on the column header and change the format to date, the numbers all change to 1905.
So, I tried to open it in Excel and change the formatting in it.
a screenshot from Excel
First, I tried to change the format to a yyyy date but the numbers turn to 1905.
I thought that maybe excel recognize the content of the columns as text so I tried to convert the text to a value in two ways (through the value() function and through multiplying the numbers by 1 then copying and pasting them as values) but whenever I change the format to a yyyy all the numbers change to 1905.
I tried the Text(,"YYYY") and it didn't work.
I tried to add a 01-01 to the column cells but it didn't work.
How can I let Excel or Power Query know that this column has years in it?
Any help will be appreciated.

Excel stores dates as serial numbers with 1=1-Jan-1900 So if you convert a number like 2000 to a date, Excel will add that number of days to 1-Jan-1900 and display the appropriate date. There is no way for Excel to know that you expect the Integer 2000 to be translated to a year.
In Excel, to translate that to a year, you can use a formula in an adjacent column =DATE(A1,1,1) => 1-Jan-2000
In PQ, you can also add a custom column with the formula =#date([year],1,1) where year is the name of your column with the year numbers, and the year column has Int64.Type or whole number

Related

Match function with dates

I have date column on two different sheets and when I run a match function (part of index match) it comes up N/A, because Excel says the two cells that have the same date in them are not equal to each other. When I change the format of one of the columns it changes to five numbers (which I know that is what excel uses to track dates), but the other column does not do this, it is simply text.
My question is, how to I get excel to forget about the five number date format and just give me text? Paste special values doesn't get it done like I thought it would.
I would say that you basically have two options: either convert both to text, or convert both to dates. If you want the text, the easiest way to convert them to text is via text to columns:
Select the column with the date (the one that turns to a 5 digit number when formatted to number or general) and select Text to Columns:
Click on next twice and select Text, then finish:
And that should do it.
I'll mention the other method, just in case, because in my experience, it's more often more practical to get the dates as actual dates in excel rather than text, especially when one wants to perform calculation on them or allow for different date formats.
The other method involves inserting 1 somewhere and copying it. Then select the set of dates that is plain text:
Use the paste special function and select 'Multiply' under the operations section:
All the dates normally should turn into those 5 digit numbers (if they were originally formatted as general for example). You simply then need to format them as date with the appropriate format, and your index/match should be fine matching the two date columns.
Excel will struggle to compare text (date as text) with numbers (date as an integer).
My suggestion is to convert the text into a 'proper' date. This is a good habit. When excel recognises something as a date it will store it as that 5-digit integer, but can display it however you choose (format cells to see the options)
So create a column next to your 'text dates'. Fill it with a formula which will create a 'proper' date, using the existing text.
If your text is in A1, then put this in B1. Assuming your data is dd/mm/yyyy
=date(right(a1,4),mid(a1,4,2),left(a1,2))
This is just saying that:
Year = rightmost 4 characters
Month= middle 2 digits (start at character 4 and grab 2 digits)
Day = leftmost 2 digits.
I assume you are using normal dates, and not the abomination that is USA format dates. But if your text is in USA data format then just swap the month and day parameters. Likewise if your text dates are 2 digits just tweak the 'year' parameter.
Check it works as expected, then copy down the column. You can now use column B for your vlookup or index match.
nb Jerry's answer is excellent and should work. I added the above because it tells you a little about how to directly work with dates. Good luck.

Converting month number from full date cell into text month in Excel

So I have a pretty long column with name dates and hours, like this:
14/01/2017 03:30
(They are DD/MM/YYYY HH:MM)
I need to get the month number and show it as text, like January, February, and so on.
If I format the destination cell as 'MMM' all the column cells show January even if the given month is 2, 3, or let's say 12. I also tried the formula =TEXT(L2,"mmmm") (since the given info come from column F.
Any ideas?
sounds like your date and time are stored as text and not in excels serial date format. You can test this by changing the format of the cell to general and seeing if anything happens if nothing changes then its text. another way would be to use the formula =istext(A1) where A1 is a cell with a date in it.
Now ASSUMING you do have dates in text format, I would suggest converting them to excels date serial. There are numerous ways of doing this. I will show you one way.
This will strip each component of the text out and then recombine it. We will assume your date in is A1
Strip out the year
=MID(A1,7,4)
Strip out the month
=MID(A1,4,2)
Strip out the day
=LEFT(A1,2)
Now to recombine it:
=DATE(MID(A1,7,4),MID(A1,4,2),LEFT(A1,2))
That will give you the date in an integer format that excel can then turn around and display as needed.
In order not to lose the time component you should strip that part off as well and combine it with the date. Remember the date is an integer, and the time is everything after the decimal. Think of time as a fraction of a day.
To get time out use:
=RIGHT(A1,5)
and to convert it to excel time:
=TIMEVALUE(RIGHT(A1,5))
and to get the two together, simply add:
=DATE(MID(A1,7,4),MID(A1,4,2),LEFT(A1,2)+TIMEVALUE(RIGHT(A1,5))
The key part to this whole thing is you will need to format that cell to display what you want. you can either choose a preformatted style from the drop down menu, or you can apply custom formatting. Setting the custom format to MMMM should display just the full name of the month.
IF you actually need the text of the month and not just the format, then you could use the formula from your question:
=TEXT(<insert appropriate formula from above>,"mmmm")
Try using MID to get the month only, then TEXT():
=TEXT(MID(A1,SEARCH("/",A1)+1,2),"MMMM")

Excel strange issue to recognise dates

I have problem in formating the dates. I have dates that are recorded manually in dd.mm.yyy format. i have converted them to dd/mm/yyyy format using Left, right and Mid functions. The problem is that excel is able to identify only some cell values as dates and rest as text. I have also tried selecting the whole date range and convert to date. But when i apply filter the dates that are not recognised by excel are shown separately and the remaining under 2015 & 2016 years.
I need all the values to be converted and identify in excel. I am attaching screen shots of the same issue
Date different format
From the picture the row range from 23 to 28 in 2nd column is identified as date and row 29 to 34 is displayed as text. When i apply filter in second column, the date is shown as in below format
Filter issue
#Rejendra, I thing the problem you are having is that your computer is thying to evaluate the dates in american format e.g MM/dd/yyyy.
If you convert the date to yyyy-MM-dd using left right and mid functions and the excel formula =DATEVALUE it should work
If your computer is set to non US format you could simply use:
=DATEVALUE(SUBSTITUTE(A1,".","/"))
to convert it where A1 is the cell with the . delimited dates

Excel date conversion and grouping

I have 20 years of week dates and their corresponding values. The date format is yyyy-mm-dd (the data is not in date format but just in this format on excel), and each of this has a corresponding value. I need to find daily, weekly, monthly, yearly averages. Since the data is too big and I can't find them manually.
Is there any way I can first convert this non-western type of date into some date types and then use some excel functions to do my calculation?
Thanks
If yyyy-mm-dd is text you should be able to convert to number by entering 1 somewhere and copying that, then selecting all the text to be converted and Paste, Paste Special..., check Multiply, OK.
You don't mention what you are averaging (a total divided by number of days/weeks/months/years involved?) but if just counting by day/week/month/year then a PivotTable should be very useful (dates for ROWS and Sum of values for VALUES), with grouping of rows to suit.

Calculate number of rows with current month & year in Google Sheets or Excel, when dates are in ISO format

I have one column filled with dates in ISO format (with header row), such as:
DATES
2015-05-13 12:46:41
2015-03-19 11:50:13
I would like to count the number of rows which match the current month & year. In the example above, the result would obviously be one (when it's May 2015).
Is this possible to achieve this result using a function in Google Spreadsheet?
Same question without ISO date can be found at:
Calculate number of rows with current month & year in Google Sheets or Excel
If those are text values, as per my comment, then the suggested formulas in the link won't work - either convert as suggested or you can use this formula to count text values that represent the current month
=COUNTIF(A:A,TEXT(TODAY(),"yyyy-mm-")&"*")
or avoiding date formats in text function
=COUNTIF(A:A,YEAR(TODAY())&"-"&TEXT(MONTH(TODAY()),"00")&"-*")
change commas to semi-colons depending on regional settings

Resources