In 2017 the Islamic month of fasting, Ramadan, began on Friday, 26 May. What fraction of the year was this? I calculated it manually as 146/365, but I am looking for an excel formula to calculate it.
If you have the date when Ramadan began on Cell A1, then:
=A1 - DATE(YEAR(A1),1,0)
or
=A1 - DATE(YEAR(A1),1,1)+1
will give you the Ramadan day of the year, to get the fraction:
=(A1 - DATE(YEAR(A1),1,0))/(DATE(YEAR(A1),12,31) - DATE(YEAR(A1),1,1)+1)
or using LET to avoid repetition:
=LET(r, A1, y, YEAR(r), (r-DATE(y,1,0))/(DATE(y,12,31) - DATE(y,1,1)+1))
You can replace the denominator using a leap year condition as follows:
=LET(r, A1, y, YEAR(A1), (r-DATE(y,1,0))/(365+IF(MONTH(DATE(y,2,29))=2,1,0)))
Related
I have a date range where I would like to find out the number of working days (excluding weekends and holidays) that fall in a range of months. Example below.
I understand this may involve a number of if/networkdays but struggling to complete this. Any help appreciated.
If you have Excel 365 you can use this formula
I am assuming that your table starts in A1 and that C1, D1 etc contain first of month date, e.g. 1.1.2022 etc..
=LET(startMonth,C$1,
endMonth,EDATE(startMonth,1)-1,
startPeriod,MAX(startMonth,$A2),
endPeriod,MIN(endMonth,$B2),
IF(startPeriod < endPeriod,NETWORKDAYS(startPeriod,endPeriod),0)
)
Setting startMonth and endMonth is more for readability of the calculations of startPeriod and endPeriod.
startPeriod will be 28.1.22 for the january column as it is greater than 1.1.22. But for febuary it will be 1.2.22 and so on.
Calculating the the networkdays is based on these two dates.
If you want to add holidays refer to the help of NETWORKDAYS
I need to recreate some of the functionality from Excel's EOMONTH function -- specifically the ability to enter a date and an integer representing a number of months in the future or past, and from those inputs calculate a new date that is the last day of the target month. I have been using Excel formulas for some simple testing and I can get close but cannot get it exactly right. So I would like to do this in Excel but without using the EOMONTH function or any of the other fancy date-related functions like EDATE or DATE or similar (because some of these automatically handle / correct some kinds of invalid data ... like months larger than 12 for example). TRUNC and MOD are fine ... and basic math operators ... but that's about it. This needs to be done in excel only -- no VBA code. We can assume the date entered is a month-end date, if that helps.
Say I have the following data in cells:
A1: 12/31/2021
A2: 1
The result in A3 or wherever should be 1/31/2022
With A1: 12/31/2021
A2: 0
A3 should be 12/31/21
A1: 12/31/2021
A2: -1
A3 should be 11/30/2021
A1: 12/31/2021
A2: -12
A3 should be 12/31/2020
I need to go up to 60 months forward or backward from any valid end-of-month date. I have been able to do what I want with a positive number (or zero) in A2, but negative numbers cause issues which I have not been able to figure out. I am using MOD + TRUNC + some basic math inside IF statements -- pretty ugly and doesn't handle negative numbers so I'm hoping there is a better way. Oh ... and I have actually been deriving Day 1 of the month following my "target month" ... and then subtracting 1 from that Day 1 date, to arrive at my target End Of Month date. This seems to me like a good way to work around the (lack of) EOMONTH function ... but I am happy to entertain any and all ideas / options.
--- New Info added 12/23 ---
I cannot simply use the EOMONTH formula because my target language (a virtual attribute in Uniquery) does not support it. So I am prototyping the solution in Excel but will implement it in the other system.
I did not include the detail below initially because A) I think there must be a more elegant solution so I am a little embarrassed about this ugliness and B) it is a lot of detail which I thought might be unnecessary. But since you asked :) here is some data from my worksheet showing what I have done and the results (and the issue).
Input:
A3 (input date): 10/15/2020
E3 (Months +/-): *** see comments below ***
Formulas:
B3 (input month): =MONTH(A3)
D3 (input Year): =YEAR(A3)
G3 (Interim New Month): =B3+E3+1 (+1 to give me the month AFTER my target month)
H3 (Month Adjustment): =MOD(G3,12)
I3 (Year Adjustment): =TRUNC(G3/12,0)
J3 (New Month): =IF(H3=0,12,H3)
K3 (New Year): =IF(H3=0,D3+I3-1,D3+I3)
L3 (Interim New Date): =J3&"/1/"&K3 (This will be day after my target date)
M3 (New / Target Date): DATEVALUE(L3)-1
With a couple dozen dates in cells A3:A27, first date = 10/15/2020, second date = 11/15/202, etc. (each date in the following month) ... and the formulas above entered on row 3 then copy/pasted down to row 27 ... and trying various values in cell E3 ... I can see the formulas work for numbers from -2 up through +60, but fail for certain months when E3 contains -3 or smaller. Specifically, with E3=-3 and input date = 1/15/21 my logic fails because the Interim New Month (column G) calculates a value of -1 which causes problems for the downstream formulas. I have addressed some of these problems with the MOD and TRUNC logic ... and the IF H3=0 logic ... but the one thing I cannot figure out is how to get the year right. With the current formulas when E3 is -3 and the base date is 1/15/21 the final year comes out 2021 which is incorrect. It should be 2020. And when E3 = -4 the base dates of 1/15/21 and 2/15/21 both produce incorrect values for Year -- 2021 instead of 2020. Smaller and Smaller E3 values produce more incorrect results.
Surely there is a relatively easy solution to this but I just cannot see it!?!?
Thanks!
Things I know:
Need to make $165,000 by the end of December to break even.
Made $48,000 so far this year (Jan-Apr).
Made $12,500 in April.
How would I figure out what my consistent growth would need to be to hit my break even point?
Doing a guess and check method I came up with 11.060176%. This means
May = $13,882.52
June = $15,417.95
July = $17,123.21
August = $19,017.06
September = $21,120.38
October = $23,456.34
November = $26,050.65
December = $28,931.89
I know the answer for this specific scenario is 11.060176% growth month over month, but that was with a lot of guess and check. How would you do this in a formulaic way.
Thanks in advance.
Place the jan-march value in A1 and the april value in A2.
Place a guess growth rate in C1 (say 1.15). In A3 enter:
=A2 * $C$1
and copy downwards. In A11 enter:
=SUM(A1:A10)
Now we bring up Solver and tell it to adjust C1 to drive A11 to the goal of $165,000:
This yields 1.00977358283576
NOTE:
The growth rate is applied using the April amount as the base.
EDIT#1
I re-ran the model with A1 reduced to $35,500 so that the sum of A1 and A2 is the required $48,000. The new Solver result is:
I am making an on-call schedule in excel and I can't for the life of me find an easy way to populate the dates. For example, someone is on call from Monday to Sunday, January 2nd - January 8th. Then the next person is on call from January 9th - January 15th. I am trying to figure out a way or formula to just "Drag" down the column and it input the next 7 day range. I have tried input the start date and end date in a separate cell, then using concatenate but it returns the date number in excel (forgot what its called). I also tried =(A1&" - "&B1) but that returns the same 5 digit number.
Any help or pointers are greatly appreciated!
Previous date + 7
If you have genuine dates, say in cells A1 "start date" and B1 "end date":
Jan 2 Jan 8
Then the next line will be
=A1+7 =B1+7
Verify Dates
To see, if the "Dates" you entered are realy dates excel can work with like that, apply "General formatting" to the A1 and B1 cells. If the resulting value is an Interer or a Decimal number, you are golden. If the resulting value did not change, you have a text and you need to apply different approach.
Perhaps you are looking for this:
=TEXT(A1,"d-mmm")&" - "&TEXT(B1,"d-mmm")
The formatting specification can be copied from the formatted cell properties.
I have an Excel 2010 workbook with this formula:
=EOMONTH("01"&TEXT(B7,"MMM")&IF(MONTH(CMVAR)<4,TEXT(YEAR(CMVAR)-1,"YYYY"),TEXT(YEAR(CMVAR),"YYYY")),0)
It resolves when you are in the cell and press Enter, however when the workbook first opens or is refreshed, the result is #VALUE!. Here are the components:
B7 =IF(OR(MONTH(CMVAR)>6,MONTH(CMVAR)<4),"Apr",IF(MONTH(CMVAR)=4,TEXT(EDATE(CMVAR,-3),"MMM"),IF(MONTH(CMVAR)=5,TEXT(EDATE(CMVAR,-3),"MMM"),TEXT(EDATE(CMVAR,-3),"MMM"))))
which equates to Apr.
CMVAR 31/03/2015
The formula is being used because in April, May, June (first three fiscal periods) we require comparison data to show in the 12-period grid from the previous financial year. From July onwards we will have comparable data from the current year and so the grid can start from April. Once the month has been determined I'm trying to work out what the date of the end of that period is, taking into account that Jan, Feb and Mar are actually periods 10, 11 and 12 of the fiscal year and so the year element of the formula will be the prior year if CMVAR shows the date to be in any of those months.
Is there a better way that avoids the error or a way to fix it?
It is not completely clear what result do you expect for different values of CMVAR, but looking at your formula, I suppose you want it to be:
You can calculate Result with the following formula:
=EOMONTH(CMVAR,-MAX(MOD(MONTH(CMVAR)-4,12),3))
If the picture above does not show your expected output, can you please prepare similar table?
EDIT:
To explain how the problem is solved, I have created additional columns with intermediate calculations:
column C is the month difference between CMVAR and expected result - the goal is to find a formula returning this number
column D calculates month of CMVAR
column E - function MOD returns the remainder after number is divided by divisor (12).
column E matches all values of C, except 0,1,2, so in column F function MAX replaces those values with 3
Your EOMONTH formula is going wrong because the TEXT part should be in the form TEXT(date,"YYYY"). YEAR(CMVAR) gives a number rather than a date.
You could use instead
=EOMONTH("01"&TEXT(B7,"MMM")&IF(MONTH(CMVAR)<4,TEXT(EDATE(CMVAR,-12),"YYYY"),TEXT(CMVAR"YYYY")),0)
or this may be easier than using the TEXT functions
=EOMONTH("01"&B7&IF(MONTH(CMVAR)<4,YEAR(CMVAR)-1,YEAR(CMVAR)),0)
Your B7 formula is OK but could be simplified to
=IF(OR(MONTH(CMVAR)>6,MONTH(CMVAR)<4),"Apr",TEXT(EDATE(CMVAR,-3),"MMM"))