How get a value looking only for last day of a given month available? - excel

In column A I have a list of dates and in column B I have values:
A B
01/01/2020 10
28/01/2020 20
03/02/2020 30
04/03/2020 40
How to get (for example value 20) looking only for last day of a given month (for example January) available?

You can use MAXIFS to get the last date in the month and VLOOKUP to get the matching value e.g. if the month number is in C2:
=VLOOKUP(MAXIFS(A2:A5,A2:A5,">="&DATE(2020,C2,1),A2:A5,"<="&EOMONTH(DATE(2020,C2,1),0)),A2:B5,2,FALSE)
EOMONTH with a zero gives you the last day in the current month (i.e. 31/1/20 in this case)

Related

Find first date after today that matches a day-number and weekday

Given any date, how do I find the first month and year in the future where the 31st of that month falls on a Wednesday, in other words, for today, 11 November 2020, I would like to see (31) March 2021. [Updated: Returned month should be March 2021]
#prino,
You could make use of Excel's Iterative Calculation, setting Maximum Iterations to 1000.
In the example below, A1 is the given date and B1 receives the result (put the formula in B1):
=IF(B1=0,A1)+B1+IF(AND(WEEKDAY(B1,1)=4,DAY(B1)=31),0,1)
If you have Excel 365 then
=LET(DayInMonth, DATE(YEAR($A$2),MONTH($A$2)+SEQUENCE(336,,0,1),$B$2),
DOW, WEEKDAY(DayInMonth),
IsMatch, (DAY(DayInMonth)=$B$2)*(DOW=$C$2)*(DayInMonth>=$A$2),
XLOOKUP(1,IsMatch,DayInMonth,,0,1))
How it works:
Parameters are on the sheet (you could hard code these into the formula if you wish)
A2 is the start date (could be formula =TODAY())
B2 is the day number in the month
C2 is the day of week code (1..7 = Sunday..Saturday)
The calander repeats every 28 years. So only need to consider 12*28 = 336 months
DayInMonth is the specified date in each of the next 336 months, including this month. Note: if a month does not have the specified day (eg 31 September does'nt exist)
DOW is the day of Week code for those dates
IsMatch is 1 if calculated DayInMonth matches specified DayInMonth (this excluded non-existant dates) AND Calculated DOW matches specified DOW AND calculated date is on or after start date
XLOOKUP returns the date of the first 1 in the IsMatch array

How to collect number of days from a month in excel

I have a column which will have some days from a month in dd-mm-yyyy format. What I need to get total number of days from each month mentioned in that column. The column might not contain all days from each month.
Example :
Column A :
2017-01-01
2017-01-02
2017-01-17
2017-01-27
2017-02-08
In above example, from 2017 Jan, I have 4 days and from Feb I have one day. I need this count for a IF statement to run in C column. ie, in C1 there will be an IF function which will check the month in A1 and count the total number of days for that specific month from A column. If that count is below a specific digit, I need to perform a formula otherwise a different one. This will repeat for all C cell
If this column contains all date from each month I can use Day function to get total days, but here how Can I collect it
This will work: =SUMPRODUCT(1*(MONTH($A1:$A5)=D1))
And an example of manipulating basing on the result:
=IF(SUMPRODUCT(1*(MONTH($A1:$A5)=D1))<3;"good";"bad")
Another one when row number represents a month (JAN in C1, FEB in C2...):
=IF(SUMPRODUCT(1*(MONTH($A1:$A5)=ROW()))<3;"good";"bad")
In your case:
=IF(SUMPRODUCT(1*(MONTH($A1:$A5)=ROW()))<10;function1();function2())
Array formula - use Ctrl+Shift+Enter:
=SUM((MONTH($A$1:$A$5)=MONTH(A1))*(YEAR($A$1:$A$5)=YEAR(A1)))

How to calculate the number of weeks between 2 date range in excel

I have a question here, I have 3 columns in excel, A1 is being the calendar date; column B1 has the fiscal_quarter_start_date ; and fiscal_quarter_end_date in column C1.
I am trying to find the number of week falling in between the A2 and A3. The issue here is I should consider the first sunday as the first week of the quarter. My fiscal year starts on Feb of every month.
The reason I am doing this calculation is to populate the count of weeks numbers of a quarter, where my first week starts from the first sunday of the quarter.
=ROUNDUP(MOD(IF(A13>=IF(DATE(YEAR($A13),2,1)=1,DATE(YEAR($A13),2,1),DATE(YEAR(A13),2,7-WEEKDAY(DATE(YEAR(A13),2,1),1)+2)),ROUNDUP((A13-IF(WEEKDAY(DATE(YEAR(A13),2,1),1)=1,DATE(YEAR($A13),2,1),DATE(YEAR($A13),2,7-WEEKDAY(DATE(YEAR($A13),2,1),1)+2))+1)/7,0),ROUNDUP((A13-IF(DATE(YEAR($A13)-1,2,1)=1,DATE(YEAR($A13)-1,2,1),DATE(YEAR($A13)-1,2,7-WEEKDAY(DATE(YEAR($A13)-1,2,1),1)+2))+1)/7,0)),13.01),0)
above is the formula i've got all the way. However rounding up with 13 is not a viable solution as its not necessary that it should have always have 13 weeks all the time.
For example: 5/1/16 should be week 1 As it is a begging of a q2 and 5/1/16 is the starting on Sunday. In this case using above formula result for the week is 13
Please help me..
You can use WEEKNUM to get the week number.
However you mentioned that your week wont end at the Saturday, but at the Sunday, so you have to do =WEEKNUM(<insert here where the date is>,2)
=WEEKNUM (serial_num, [return_type])
serial_num - A valid Excel date in serial number format.
return_type - [optional] The day the week begins. Default is 1.
Return_type can either be 1 or 2:
1 - Week begins on Sunday
2 - Week begins on Monday
or... read it here for counting weeks between 2 dates.
Enter this formula =(A2-A1)/7 into a blank cell, (A2 indicates the end date and A1 is the start date)
If you just want to get the whole weeks, please apply this INT function: =INT((A2-A1)/7)
Try it here, on sheet "week"
Hope it'll help.
Assuming that the Quarter start and end dates are in A3:A6 respectively then:
=IF(AND(C1>=$A3,C1<$A4),WEEKNUM(C1)-WEEKNUM($A3)+1,IF(AND(C1>=$A4,C1<$A5),WEEKNUM(C1)-WEEKNUM($A4)+1,IF(AND(C1>=$A5,C1<$A6),WEEKNUM(C1)-WEEKNUM($A5)+1,WEEKNUM(C1)-WEEKNUM($A6)+(IF(AND(C1>=DATE(YEAR(C1),1,1),C1<DATE(YEAR(C1),MONTH($A6),DAY($A6))),53,1)))))
This is checking whether the date in the cell above (C1) is between the quarter start and end dates, and checking the difference in weeks from the start date. To cover the anomoly for Q4 extending into the next year, the IF statement at the end adds 53 instead of 1 for the affected dates.
Edit #1
=WEEKNUM(A1)-WEEKNUM(B1)+IF(AND(A1>=DATE(YEAR(A1),1,1),A1<DATE(YEAR(A1),MONTH(B1),DAY(B1))),53,1)
This works for the A1:C1 format you mentioned in your comment. Obviously this relies on B1 and C1 being updated manually.
Edit #2
=WEEKNUM(C1)-WEEKNUM(B1)
If you are counting 05/01/2016 as week 1 then add 1 to the result. Take off the highest week number (default is counting from sunday or you can change to (C1,1) if you want to define it exactly) from the lowest week number. Reult is 13 which would match the manual calculation.
You will want to look at the previous edit for an example of the if formula you will need when the quarter ends in another year. to reverse the negative figure it will need to add 52 when the date is in the early part of the next year and 0 when it is not.
You can use the "hidden" function DATEDIF:
For example in A1 we write start date (01/05/2016), in B1 - end date (31/07/2016) and in C1 = DATEDIF(A1,B1,"d")/7 the result will be 13

Find last digits with IF

I have lots of cells in the spreadsheet that contains the whole year, date and stock prices, but I only need the dates from 25th of the last month till the 5th of this month.How can I write a function to do that? For example if the cells are like this in the column:
19900101
19900102
19900103
19900104
19900105
.
.
19900125
19900126
19900127
19900128
19900129
19900130
19900131
I want it to show only days (1,2,3,4,5,25,26,27,28,29,30,31) with the date format.
The date shows in the text format and I've tried format cell to change it but it doesn't work.
For a slightly different approach, assuming you want to return the A2 value only if it represents a date in the last 5 or first 5 days of any month you can use this formula in B2
=IF(DAY(TEXT(A2,"0000-00-00")+5)<11,A2,"")
TEXT function converts your data to a real date then if you add 5 days to that date then any date that was originally in the last 5 or first 5 of the month will now be in the first 10 days of the month.....so it's sufficient to check that the day is < 11. That will pick up 27th to 31st of a 31 day month, 26th to 30th of a 30 day month etc.
you could use a formula and then filter by rows with data...
As an example (given it's difficult to discern if you always want the first 5 and last 5 of a month or what....)
=IF(RIGHT(A2,2)*1<=2,A2,IF(RIGHT(A2,2)*1>=29,A2,""))
Based on all the edits and comments, these should be the function you need.
=IF(OR(A7-A2>5,MOD(A2,100)<=5),DATE(LEFT(A2,4),MID(A2,5,2),RIGHT(A2,2)),"")
You should place it in cell B2 and then do all the desired filtering, as explained in xQbert's answer.

Google Spreadsheet: Find the largest number within a date range

I have three columns. One has a date, one a numerical value, and the last a text value. I want to call from a different sheet the nth largest number within the last month, and then in the cell beside it, the text value corresponding with that row. The column headers are named ranges for ease, and titled Amount, Date and Name.
Amount Date Name
------ ----------- --------
5 11/11/2013 Fred
30 5/11/2013 Bob
5.2 23/11/2013 Jack
40 29/10/2013 Tim
If I wanted to just get biggest number, I could do "=Large(Amount;1)" which would return 40, but I'm looking to get the largest amount in the last month (not just the last 30 days) which should return 30.
What I'm currently doing to pull the name (which will give name next to the largest value, not the largest value in the last month) is "=INDEX(Name,MATCH(Large(Amount;1),Amount,0))"
All of this is being done in Google Drive on their spreadsheet.
Thanks!
You can use the filter function, like this:
=LARGE(FILTER(A:A, YEAR(B:B) = 2013, MONTH(B:B) = 11), 1)
This means: get the max value from column A filtered based on the B column, where year is 2013 and month is 11.
zord's answer looks good for November 2013 but I think you want the "last month" so on December 15th assuming you want any date after November 15th then you can use a similar approach but use EDATE function to get a date one month back from today, i.e.
=LARGE(FILTER(A:A,B:B>EDATE(TODAY(),-1)),1)

Resources