Using COUNTIFS with different date formats - excel

I am trying to calculate the totals of a column when the date column is within a certain month. The value to find is in a different date format to the format in the criteria range and I can't figure out how create a formula using the two different date formats. Here are the columns where I am trying to get the totals from:
Here is where I am trying to count the rows when it falls within a certain month and year:
This is the formula I have created but this doesn't work and just returns 0:
=COUNTIFS($A$3:$A$27, YEAR(G3), $A$3:$A$27, MONTH(G3))
I have also tried this but it is still returning 0:
=COUNTIFS($A$3:$A$27, "=YEAR(G3)", $A$3:$A$27, "=MONTH(G3)")

Format is irrelevant if your dates are REAL dates
If your dates are "real" dates, merely formatted a certain way
And if your Months are also real dates where the date is actually the first of the month,
Then:
=COUNTIFS(Dates,">="&B15,Dates,"<=" &EOMONTH(B15,0))
Where Dates is the Named Range containing your list of dates, and B15 contains your month/year formatted first of the month date.
If your months column is not the first of the month, then a minor change is all that is needed to convert the first criteria to the first of the month:
=COUNTIFS(Dates,">="&DATE(YEAR(B15),MONTH(B15),1),Dates,"<=" &EOMONTH(B15,0))

Related

Conditions in Excel: skip cells with dates without a year

I have the results of a survey with birthdays in various date formattings.
01.01.1990
02/03
04.05 etc.
Every time Excel sees a day and a month without a year it implies the current year and puts it in the cell without any hesitation. So, when we try to extract a year, we get not the error we expected but the current year, which is nonsense.
How can we avoid this behaviour?
The desireable result is:
One column with one formula
If the year is written, we extract it using =YEAR()
If it is absent, we just do anything else, for instanse put "".
Basic change of formatting doesn't change the implication of the current year. And if we change the format of the whole column from date to text, we cannot use the formula "YEAR" anymore to any of the cells.
This is a task for students who can deal with Excel and Google Sheets only, Python is not an option.
I would be very grateful for any help!
Both Excel and Google Sheets stores date as a number (day count) starting from 1900/01/01 so it either assumes year for you or doesn't recognize it as date at all.
If you convert date to number, 1900/01/01 will be 1, 2023/01/16 will be 44942 (as it is 44942 day counting from 1900/01/01).
I assume that survey can't be filled by people born this year so just "filter" them out:
If date is in A1 use formula:
=IF(OR(YEAR(A1)=2023,YEAR(A1)=1900),"",YEAR(A1))
This will print nothing if captured year is 2023 or 1900 (this behavior also possible when dealing with dates without years).

Count How Many License Registered in the specific month

How to formula using CountIf function in Excel to get the count of licenses registered in January given the Register date is complete date format. Below is the sample structure of Excel data. As shown in the table below, there are 3 licenses registered in the month of January.
You can add a new column for the month, which I'll call B, and put the following function in the first cell of that column, and then copy it down:
=Month(B1:B4)
Then where you want the count to appear (I used C5), use the following formula:
=CountIf(B1:B5, 1)
This displays the following results:
This correctly performs the count regardless of the date format for the cell, as long as it's a date. In other words, it works for mm/dd/yyyy, d/m/yyyy, dd/mm/yyyy, and yyyy/mm/dd equally as well, which removes the issue of trying to parse out the first two characters of a string.
I tried various methods but i had to unfortunately use helper column to extract month number from dates. I used left function to extract month number as Left(B2,2). Then i used countif function to count all cells have "01" countif(C2:C6,"01"). This is not the best solution but it worked.

Excel - count days between two dates per year

I am trying to get the number of days per year between two dates.
The results should look somehow like the following picture
The range between the 2 dates in the 2021 year has 301 days and in the 2022 year has 94 days.
Put this in C2 and copy over:
=MIN(DATE(C1,12,31),$B$2)-MAX(DATE(C1,1,1),$A$2)
Your question isn't entirely easy to understand but what you don't know is in plain sight: Excel represents dates as integer numbers where Jan 1, 1900 is the first day (= 1) and all days from then till now have a unique number. Today is 44261. Tomorrow will be 44262.
Therefore the difference between dates equals [End date] - [Start date], where only one of these two dates is included in the count. [Tomorrow]-[Today] = 1, not 2.
When a worksheet cell is formatted as General Excel will automatically change that format to whatever Excel thinks you have probably entered. If you enter what Excel recognizes as a date the cell format will be changed to Date and if the way you entered the date was by function, such as =TODAY() the cell will display "6/3/2021" using the date format specified in your Windows International settings.
But if you manually change the cell format back to General or Number the display will change to 44262. That's the way you can test if your cell contains a "true" date, with which you can do calculations, or a "fake" date, which is just a text string which is nice to look at but otherwise useless.

Calculate monthly average from daily data without PivotTable

My worksheet contains two columns: column A contains the date in the format dd/mm/yyyy and column B contains the daily data. From the daily data I have to generate the monthly average for each month without a PivotTable. Some of the days contain no data at all. I cannot use a PivotTable as I have to use the monthly average to identify outliers in the daily data at a later stage.
For this example it's important that I don't use a PivotTable and that I can generate the monthly average data for any month and year in my list. The solution can be an Excel formula or VBA.
Assuming you have the months in column D enter this formula in E2 and copy till last month
=AVERAGEIFS($B$1:$B$62,$A$1:$A$62,">="&D2,$A$1:$A$62,"<="&EOMONTH(D2,0))
Some of the days contain no data at all.
In case this means that there are no row for some dates and you want to calculate average based on full month than you can use the below formula:
Continuing with example given by EEM
=SUMIFS($B$1:$B$62,$A$1:$A$62,">="&D2,$A$1:$A$62,"<="&EOMONTH(D2,0))/DAY(EOMONTH(D2,0))
In case Daily Data contains some #N/A, one can add a additional criteria to skip non number data:
=AVERAGEIFS($B$1:$B$62,$A$1:$A$62,">="&D2,$A$1:$A$62,"<="&EOMONTH(D2,0),$B$1:$B$62,"<10E69")
Given a single date you can calculate both the End of the Month and the First of the Month for that date. Assume any given date is in E4:
For the End of the Month
=EOMONTH(E4,0)
For the First of the Month
=EOMONTH(EDATE(E4,-1),0)+1
If you place a date, any date, of the month you want to review into cell E4 the two above code snipets will give you and last and first days of the month. EDATE allows you to add and subtract whole numbers to change the month. We take one month away from the current month, found within the date in cell E4, and then find the end of the month and add a one to it to become the first day of the next month. It will work with any date. The below example shows grade averages over a month referencing any given date within the month.
Pic of the above Excel example
=AVERAGEIFS(C2:C11, B2:B11,">=" & EOMONTH(EDATE(E4,-1),0)+1, B2:B11,"<=" &EOMONTH(E4,0), A2:A11, E2)

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