How to calculate - excel

My question is almost identical to this one: Calculating number of days between two dates dependent on month
But I have data that is a rolling 12-months and I need to have additional coding added to the formula:
=IFERROR(IF(AND(MONTH($D2)=F$1,MONTH($E2)=F$1),$E2-$D2,
IF(MONTH($D2)=F$1,1+EOMONTH($D2,0)-$D2,
IF(MONTH($E2)=F$1,$E2-DATE(YEAR($E2),F$1,1),
IF(AND(MONTH($D2)
F$1,MONTH($E2)>F$1),DAYSINMONTH(DATE(YEAR($D2),F$1,1)),0)))),0)
to allow for a reservation that is for February 2018, for example, to show in its own column, and not be included in February 2017.
For example, my data might have:
John Smith, arr 2/21/17 dep 2/18/17
& Matt Jones, arr 2/21/18 dep 2/18/18
and currently the way I have my document built, it would show 2 for column "2", aka February. I need it to show 1 for Feb-17 and 1 for Feb-18.
Can you help please and thank you!

It took me a while to work out what you're looking for but here's what I think you need.
I started from scratch on the formula so I take a different approach to the one in your question.
=IF(AND(A3<E3,D3<EDATE(A3,1)),IF(AND(A3>D3,E3>(EDATE(A3,1))),(E3-D3)-((E3-(EDATE(A3,1)))+(A3-D3)),IF(E3>(EDATE(A3,1)),(E3-D3)-(E3-(EDATE(A3,1))),IF(A3>D3,(E3-D3)-(A3-D3),E3-D3))),0)
The month that you want to check should be entered as a date, the 1st of the month.
How it works
It's easier to show by example
month to be checked date 01/02/2017
arr date: 27/02/2017
dep date: 02/03/2017
get the end of the month period to be checked date + 1 month EDATE(01/02/2017,1) = 01/03/2017
is the dep date later than the end of the period to be checked? YES
02/03/2017 - 01/03/2017 = 1 (1st value)
get days between arr and dep date 02/03/2017 - 27/02/2017 = 2 (2nd value)
2nd value - 1st value = 1
the example calculation only describes when the arr and dep dates overlap the end of the period to be checked but the formula check for an overlap at the start and also when the entire period to be checked is overlapped and arr date in Jan and dep date in Mar.
The first IF(AND(A3
I hope that explanation helps you to pick the formula apart.

Related

Distribution of a time span across months

I a process have a Start date of 1/1/2022 and end date of 3/15/2022, date is in it's own field.
Now I have a field for every Month in the Year: J F M A M etc.
I want to calculate that my process covers 100% of January and February and 50% of March. In order to calculate this, I added the start and end date for each month below the field like this :
Screenshot
Any help how I can calculate this would be appreciated.

How to find a trend/forecast result 14 days from today

I have looked into the Forcast & Trend formula but I cannot figure it out for the life of me.
I want to work out the trend 14 days from now.
I have a set of data:
A1 - A30 with dates
B1 - B30 with daily ticket count for the business.
I would like to make a result in another cell that would predict what the estimated total ticket count would be 14 days from now. I do not need all 14 days, just the 14th day.
If I was to try show you what the formula looks like in my head it would be:
=trend/forecast(B1:B30,14)
or
=Predict(B1:B30)*14
Unfortunately it is not as easy as that. How can I do this?
I think you want to use the Forecast function. The inputs you have do not match the correct format though.
FORECAST( x, known y's, known x's) where...
x = the series (or date) you want to forecast
known y's = historical tickets per day
known x's = historical dates (or series)
The below example allows you to forecast tickets for any date (Forecasted Date) given the historical information (table on left). If your table is not formatted with actual dates, just create a series (first day = 1, second day = 2, etc.) and forecast that way.
Given the historical data, the forecasted tickets for Aug 28th (14 days after last known value) are 16.7

Generate "duplicate" row if between a date there is more than one month involved

I'm asked to "automatize" some Excel tasks regarding medical licenses, what I mainly need right now is to identify if a license is longer than a month period, if so, duplicate the entire row data besides the date which needs to be adapted on the "next month" and also generate a period id that includes the year + month (e.g. 201801 for a license started in Jan/2018).
What I did first was checking and displaying if a license is longer than x period (did a loop that counts days and identify if it matches with the month above the cell), so if one started on Jan and ended in Feb it would show like this:
period id member start date end date jan feb
201801 john doe 09/01/2018 07/02/2018 23 7
=SUMAPRODUCTO(--(TEXTO(FILA(INDIRECTO($J9 & ":" & SI($K9="";HOY();$K9)));"MMM")=N$8))
The problem with the table above is that the file becomes humongous with the formula, so instead I'm thinking, for now, just the row duplication:
period id member start date end date
201801 john doe 09/01/2018 31/01/2018
201802 john doe 01/02/2018 07/02/2018
The thing is I can't figure how to compare months and print them the way I have to.
Sub CopyData()
Set hojatst = Sheets(Hoja5)
Dim d
Dim j
d = 1
j = 8
Do Until IsEmpty(hojatst.Range("D" & j))
If hojatst.Range("D" & j) < hojatst.Range("E" & j) Then
d = d + 1
End If
j = j + 1
End Sub
This is a 'sketch' of the code you will need to write. Stackoverflow is not a code request service and so you need to do your best to write it yourself. The community is happy to help you troubleshoot while you learn, but you should be using Google a lot. I wrote out the sketch to get you started because I remember how hard it was to learn the basics of coding. Feel free to ask clarifying questions.
First of all I cannot get Excel to recognize the DD/MM/YYYY format. It might be because mine is a US copy and that is not a standard time format here. You seem to be using a different version of Excel due to the formulas you listed. However be sure to double check that your code is correctly reading the DD/MM/YYYY format as you proceed.
Create a variable cl that is your current line. Create md which is the month difference.
If Month (Start Date) is less than Month(End Date) Then md = Difference of Months, insert that many lines below the current line. Range("E" & cl+md).Value = Range("E" & cl)which pastes your end date to the last slot.
Then for cl < cl+md fill in the periods by add +1 to the value if the last number is not 4 and +97 if it is.
Then fill in the blank cells for the dates with the Start of Month and End of Month dates.
Finally set cl = cl + md + 1 and loop to move on to the next 'original' line.

How do I write an Excel formula to compare year-to-date to prior years & also account for leap years?

I’m trying to compare a measure as of today through the same day and month for the prior 4 years (e.g. through June 6 of 2016, 2015, 2014, etc.).
For each year, I decided to count the number of days since the beginning of the year, and sum my values through that number of days for each year.
To identify whether a date should be included in the year to date comparison, I used the formula where my date is in cell A1:
=IF((A1-DATE(YEAR(A1),1,1)+1)<=(TODAY()-DATE(YEAR(TODAY()),1,1)+1),1,0)
I’m looking for a way around the issue of the extra day added to leap years. In other words, after February 28th, the day count will always be off by one in a leap year, and trying to use Februrary 29th in a non-leap year will return an error.
I’d like to adjust this formula, but I’m open to using a different function & formula if it gets me the right results.
you can check any information about February, 29th. If an error occurs, you know its no leap year. Catch that error with =IFERROR(;).
Assuming a table structure like this:
A:Date | B:Value
----------------------
01/01/2016 | 0
01/01/2015 | 1
01/01/2014 | 2
01/01/2013 | 3
01/01/2012 | 4
Formula
To - for example - calculate the average of the previous four (excluding the current) years on January 1st (today is 01/01/2016):
=SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
(B:B)
) / (
SUMPRODUCT(
(MONTH(A:A)=MONTH(compare))*
(DAY(A:A)=DAY(compare))*
(YEAR(A:A)>YEAR(compare)-5)*
(YEAR(A:A)<YEAR(compare))*
1
)
)
Result
For the above example, the result is 2.5
Explanation
To select only those rows representing the same month and day:
(MONTH(A:A)=MONTH(compare))*(DAY(A:A)=DAY(compare))
To select only those values from the previous 4 years (excluding the current):
(YEAR(A:A)>YEAR(compare)-5)*(YEAR(A:A)<YEAR(compare))*
The actual values we are interested in:
(B:B)
Divide by 4 for the average over the last four years. This assumes there is no missing data which might be an issue. You could use another SUMPRODUCT (replace B:B with 1) to count the number of resulting rows and divide by that number to handles this case. This seems to be rather slow, but it works.
Note
For performance reason you should not use A:A (a full column) in the formula, just use the actual range you need, which will likely be much faster.

Excel find date difference between minimum and maximum date in month

I'm trying to fix up a formula I have that's having some issues. It's supposed to track # days invoiced in a month, so the high-level idea is to take the maximum date in a month and subtract the minimum date in the month, and on error subtract the 1st day of the month. My current formula has issues adjust for invoices that may cross months, an example being 1/25 - 2/3 where if this were the only invoice, January should show 7 days invoiced and February would show 3. If there were another invoice from 2/15 - 2/28, I would want Feb to show the maxed invoice days, 14 in this example.
For reference here's what a table could look like:
A B C D E F
start month end month invoice begin invoice end Month Max Days invoiced
jan 1 feb 1 1/25/14 2/3/14 1/1 7
feb 1 feb 1 2/15/14 2/28/14 2/1 14
3/1
etc.........
I tried the formula below but it was erroring out, plus I don't think it will account for gaps in invoices like in my example.:
=IF(B2:B100=X1,MAX(D2:D100),) - IF(A2:A100=X2,MIN(C2:C100),A2)
'where column X is a list of months, X1 = 1/1, X2 = 2/1, etc.
No luck with this formula either, keeps erroring out and giving 0 values:
{=DATEDIF(IF(A2:A100=E2,MIN(C2:C100),),IF(B2:B100=E2,MAX(D2:D100),),"d")}
I appreciate your help!
Not sure exactly what you are looking for but you could probably make use of the EOMONTH() function. Here's an example of it:
=EOMONTH(A2,0)-A2+1
by the way - here is how you would get the start of the month:
=EOMONTH(TODAY(),-1)+1
Try the following per your comment below:
"I think this could be useful but I'm not sure it would work if the invoice end was, say, 2/21 or anytime before the EOM"
=IF(B3>=EOMONTH(A3,0),EOMONTH(A3,0)-A3+1,B3-A3+1)

Resources