Excel formula to derive next available date basis uneven frequency - excel

Below is a table where Column A has given date, and Column C through I are days on which future dates can occur. 0 stand for cannot occur, 1 stand for can occur.
Basis the occurrence, I am trying to figure out a formula which can tell me what is the next available date.
For Ex: In case of Monday 8th Jun, Mon is 0, hence next available date is Tue 8th Jun
For Ex: In case of Sunday 13th Jun, Mon & Sun are 0, hence next available date is Tue 15th Jun.
While (if) formula can handle this, but the frequency nature is dynamic hence need a smarter approach.
Preferably a formula based approach.

Use the following array formula in B2:
=A2+IFERROR(SMALL(IF(($C$2:$I$2=1)*(COLUMN($C$2:$I$2)>=WEEKDAY(A2,2)+2),COLUMN($C$2:$I$2)),1)-WEEKDAY(A2,2)-2,SMALL(IF($C$2:$I$2=1,COLUMN($C$2:$I$2)),1)-WEEKDAY(A2,2)-2+7)
Array-formula is entered with ctrl+shift+enter
WEEKDAY(A2,2) returns the number of the day in the week: 1 for Monday, 2 for Tuesday, etc. SMALL(IF(($C$2:$I$2=1)*(COLUMN($C$2:$I$2)>=WEEKDAY(A2,2)+2),COLUMN($C$2:$I$2)),1)-WEEKDAY(A2,2)-2 This part makes an array of the current row and returns the smallest column number that meet the following conditions: 1) cell in the range (row) has value 1. 2) the column number of the cells resulting from condition 1 is equal to or greater than the calculated WEEKDAY +2 (weekday for Monday = 1+2 =3) so if column 3 contains value 1 it's a hit, else it will look for the first next column that does meet the conditions. As the desired result should return the date of the result we add the column of the result of this evaluation to the original date and extract the WEEKDAY -2 (minus, because we need to extract *more). The IFERROR is built to search in the next row if there is no value 1 in the column equal to or greater than weekday +2. In that case it would return the first column of the next row containing value 1.

If you have Excel 2019 or Excel 365, in B, you could put the formula:
=LET( gDate, A2,
pattern, C2:I2,
s, SEQUENCE( 7, 7, 0 ),
k, MOD( s, 8 ) - ( INT(s/7) > MOD(s,7) ),
gDate + MIN( IF( pattern > 0, INDEX( k, WEEKDAY( gDate,3 )+1, ) ) ) )
I keep thinking that there has to be a simpler way than this, but none of my simpler approaches generate the results you are trying to achieve.

Related

excel formula for previous quarters

I am looking for a formula to pull up the previous quarter and year like in the Column J, for the Oct 20, it should return Q3 20 instead of Q4 20.
Currently my formula only returns the correct quarter but I would need the previous to last quarter and year?
To return the quarter | year corresponding to 3 months ago, i.e. :
"previous quarter & year"
simply replace col H date references with edate(date,-3). Cell J17 formula to enter is then:
="Q"&ROUNDUP(MONTH(EDATE(H17,-3))/3,0)&" "&YEAR(EDATE(H17,-3))
If you have Office 365 compatible version of Excel, you could shorten (albeit ever so slightly in this case) with the let function as so:
=LET(x,EDATE(H17,-3),"Q"&ROUNDUP(MONTH(x)/3,0)&" "&YEAR(x))

How to assemble Offset function with Condition?

I Have date data in Column A and values data in Column B.
My aim goal is that for each date in column A :
look if one value (column B) during 1 year is less than 90% of the corresponding Value of the date.
This is my data:
Output example :
I start at the first date (31/12/1986) and see the 900.82 value.
I calcul 900.82 * 0.9 = 810.73
So i look if value in line 3 is inferior to 810.73,
If not
I look if value in line 4 is inferior to 810.73,
line 5, 6, 7 ,8..... during 1 year (that mean I stop this the 31/12/1987).
If it is
I stop and i look the next date (01/01/1987) and do the same.
I am agree to translate it in VBA code, but it could be better on Excel.
I first tried an algo to understand the problem :
-Look the first date in column A
-Look the corresponding value in Column B and save it as Value
-Offset to the next date in column A
-Look the corresponding value in Column B and save it as Range.to.compare
-If Range.to.compare < Value * 90% then write "ok" in Column C
-Else, Offset to the next date in column A...
-Untill 1 Year (Untill Year(Date in Column A)<Year(Date in Column A) +1
I try to translate it in Excel or VBA.
This this what I tried by Excel :
But it works only for 1 day instead of 1 year
I think this is what you're after. I broke the calculation into multiple columns to show the steps.
First I calculate the 90% value, in column C.
Column D is where most of the magic happens. In column D I find all rows that have a date < the current date + 1 year, and get the value (Col B) for each of those rows. I then take the minimum of all those values. Note this is an array formula so you need to press shift-ctrl-enter after you type it in.
Now that I have the minimum from the each range, I just need to compare that with the 90% value.

excel nearest due date

I have a row with dates and below it I have an empty row where I can type a "C" on any number of cells wanted or needed to get the dates above it, but I only get the first C, so what I am trying to do is actually ignore every "C" that I have wrote that correspond to past dates from today and only give me the closer one or next one from today.
For example: lets say that today is July 1 2018, so I have row 1 with a series of dates like A1=June 30 2018, B1= July 1 2018, C1=July 2 2018, D1=July 3 2018, etc and in row2 I have typed C on A2, C2 and E2 so with HLOOKUP it returnsJune 30 2018`, but I dont want that since that date is now in the past, I want to get the next and more close date after the present day so it should be C2 that is July 2 2018, and so on since the today formula will update as the days pass.
This is to get the next checking date on a project cronogram so all the dates are defined but the result as for each task should be automatically updating to stay relevant for the scehdule, so past dates just dont make any sence to be the results showed on the gantt table diagram, and yes I know it is easy as just to be deleating the "C" that correspond to past dates, but then what is the point of excel then?
I'll go out on a limb here.... you want to find the first C in row 2 after todays date which is in row 1.
MATCH will tell you which column todays date is in: MATCH(TODAY(),$1:$1,0) returns 3 as 2nd July is in C1.
INDEX will return a reference to the cell below todays date when used in conjunction with MATCH: INDEX($2:$2,,MATCH(TODAY(),$1:$1,0))
COUNTA will tell you the last column that's populated with dates in row 1: COUNTA($1:$1) returns 9 in my case as I've put dates from A1:I1.
Use INDEX again to return a reference to the last cell in row 2. INDEX($2:$2,,COUNTA($1:$1))
Stick both INDEX's together to get a range reference from todays date to the end of you data: INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)) - this returns an error as it's returning the reference to multiple cells.
Now find the first C in the referenced range: MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0) returns 1 as I've got a C in 2nd July.
Add the column that todays date is on to the column that was returned (and minus 1 for the hell of it). SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0)) returns the column number of the first C on or after todays date.
Use that number to return a reference to the date in row 1: =INDEX($1:$1,,SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0))).
So your final formula is:
=INDEX($1:$1,,SUM(-1,MATCH(TODAY(),$1:$1,0),MATCH("C",INDEX($2:$2,,MATCH(TODAY(),$1:$1,0)):INDEX($2:$2,,COUNTA($1:$1)),0)))
Bit long, and I'm sure it can be done in a much shorter formula.
Edit: I also agree with Rawrplus - you could've explained it a bit better.

Calculate the week number of a given date using a given a reference year

I have a formula which calculates the week number of a given date:
=WEEKNUM(Sheet2!N83)
I want a formula which returns the week number using 2018 as reference, in a similar manner as the above formula does. If the year is 2019, I want it to return weeknum + 52, so for 2019-01-01 I get week number '53'.
How can I achieve this?
This is only valid for years 2018 and 2019:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(Sheet2!N83)+52)
or:
=IF(YEAR(Sheet2!N83)=2018,WEEKNUM(Sheet2!N83),WEEKNUM(DATE(2018,MONTH(Sheet2!N83),DAY(Sheet2!N83)))+52)
You actually need a formula which calculates the difference in weeks.
In A1 cell, fill the first day of the reference year (e.g. 2018-01-01).
In A2 cell, put the day of the week of your interest (e.g. 2019-01-03).
In the A3 cell, use this formula to calculate the difference in weeks (in case your week begins at Mondays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-2), B2, "d") / 7), 0) + 1
Or this one (in case your week begins at Sundays):
=ROUNDDOWN((DATEDIF(B1-WEEKDAY(B1-1), B2, "d") / 7), 0) + 1

Dynamic starting point of OFFSET and SUM formula

I have the following Excel spreadsheet:
A B C D E F G
1 Year 2015 2016 2017 2018 2019 2020
2 Revenue 5.000 4.000 6.000
3 Years to go back: 2
4 Sum of Periods: 10.000
In Row 1 you can find the years 2015 til 2020 and in Row 2 the corresponding revenue of each year.
In Cell C3 the user should input the number of years to go back and sum up the revenues. For example if the user puts in a 2 Excel goes back 2 years and sums up the revenue of 2017 and 2016 which is 10.000 in the case above. For this I used the following formula:
=SUM(OFFSET($E$2,0,-C3):$E$2)
This formula and the described calculation above work perfectly so far.
However, in 2018 I will have to adjust the starting point of Cell $E$2 in the formula above to Cell $F$2. Ohterwise the year 2018 will be excluded from the calculation.
=SUM(OFFSET($F$2,0,-C3):$F$2)
My question is now how can I avoid this permanent re-adjustment every year?
--> I think the solution should be a formula that identifies the first "non empty" cell within in a Row and then starts counting back the years from this cell. Somehow a combination of the SUM, OFFSET, ROW & COLUMN formula.
You may use this formula:
=SUM(INDIRECT("R2C" & (MATCH(YEAR(TODAY()),$1:$1,0) - $C$3 + 1) & ":R2C" & MATCH(YEAR(TODAY()),$1:$1,0), FALSE))
But be aware I'm assume the current year - $C$3 is within your data range.
Brief explain:
YEAR(TODAY()) - it will return the year of current date, then you don't need to re-adjust every year
MATCH(lookup_value, lookup_array, match_type) - it will find the value matched in first row, and return the index of cell
INDIRECT() - Form the result of match to a R1C1 notation, and convert the text to excel range
A simpler formula could be to use the 4th parameter of OFFSET to set the width and to calculate the starting point of the OFFSET using YEAR(TODAY()0-2016
=SUM(OFFSET($B$2,0,YEAR(TODAY())-$C$1,1,$B$3))
NON VOLATILE OPTION
Well non volatile if it were not for the TODAY() function. Replace TODAY() with a cell containing the starting year as a date. or replace Year(Today()) with a cell reference just containing the year (integer) and then it will be a non volatile option.
=SUM(INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)):INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)-($C$3-1))
Volatile functions recalculate every time something on the spreadsheet changes.
Non volatile functions only recalculate when something affecting them changes.
The index function returns the cell address with in the range its looking. for a 2D range you need to give row and column reference. For a 1D range, you only need to give find the position within the range.
Match finds a value within a given range.

Resources