My Task is to get Season name from Date in Excel using a formula.
So far I achieved getting Month name from Date thanks to this link:
http://dedicatedexcel.com/how-to-convert-a-date-into-a-month-name-in-excel-2010/
Is there anyway (like switch-case) in Excel formulas so I can get Season name based on month name?
Thanks.
You can use the Choose() function for that. When exactly a season starts may be open to debate. This formula assumes that the season starts at the first of the month, not the solstice and equinox days.
The formula for the Northern Hemisphere in B2 is
=CHOOSE(MONTH(A2),"Winter","Winter","Spring","Spring","Spring","Summer","Summer","Summer","Autumn","Autumn","Autumn","Winter")
The formula for the Southern Hemisphere in C2 is
=CHOOSE(MONTH(A2),"Summer","Summer","Autumn","Autumn","Autumn","Winter","Winter","Winter","Spring","Spring","Spring","Summer")
If you want the seasons to begin at the solstice and equinox dates, then use this for Northern hemisphere:
=IF(DAY(A2)<22,CHOOSE(MONTH(A2),"Winter","Winter","Winter","Spring","Spring","Spring","Summer","Summer","Summer","Autumn","Autumn","Autumn","Winter"),CHOOSE(MONTH(A2),"Winter","Winter","Spring","Spring","Spring","Summer","Summer","Summer","Autumn","Autumn","Autumn","Winter"))
There are two definitions of seasons; the Astronomical Seasons (AS), and the Meteorological Seasons (MS). the AS depend on equinoxes and solstices. I.e. they start on 21st of months. while the MS are easier for weather forecasting and so, and they start in the 1st of months.
The seasons also depend on the location (northern or southern the hemisphere.
Here are the dates and corresponding seasons depending on the location and method:
Season at
(Northern/Southern)
Hemisphere Astronomical Meteorological
Winter / Summer 21/12 to 20/03 01/12 to end/02
Spring / Fall* 21/03 to 20/06 01/03 to 30/05
Summer / Winter 21/06 to 20/09 01/06 to 31/08
Fall* / Spring 21/09 to 20/12 01/09 to 31/01
In Excel we can get the Day of Year (DOY) by the following formula:
If you store the date in cell G5 for example, then DOY =
=G5-DATE(YEAR(G5),1,1)
For (AS): The corresponding DOY of 21/03, 21/06, and 21/09 are 80, 172, 264
For (MS): The corresponding DOY of 01/03, 01/06, and 01/09 are 60, 152, 244
Although the Choose formulas above are awesome, but I would write it in simple if conditions to be easily transformed to any programming language.
Example:
The Astronomical season of the Northern hemisphere is calculated as follows:
=if((DOY<80,"Winter",iF(DOY<172,"Spring",iF(DOY<264,"Summer","Fall")))
To calculate the season for southern hemisphere or for the meteorological method, one can use the above table to modify the equation easily.
Fall is called Autumn in some parts of the world.
Assuming the Month name is in A1, and Winter begins in January, use:
=IF(MONTH(DATEVALUE(A1 & " 1"))<4,"Winter",IF(MONTH(DATEVALUE(A1 & " 1"))<7,"Spring",IF(MONTH(DATEVALUE(A1 & " 1"))<10,"Summer","Autumn")))
shorter version: =LOOKUP(MONTH(TODAY()),{1,2,5,8,11;"Winter","Spring","Summer","Fall","Winter"})
Related
I have a question related to EXCEL:
Since I have the following prices for different period, how can I compute in an automatic way, for example the price between 10 June - 15 July ?
EDIT--> Expected output:
50€+50€ (10-11 june) + 58€x13 (period 12 june - 25 June) + 75€x13 (period 26 june - 9 July) + 92€x5 (period 10 july-15july) = 2289€
This is the same pictures with the cells in excel, please do not consider the "Price of period", but only the daily price
You could do this with a (lengthy) calculation:
Consider:
A8 Contains the from date (10-06-2021)
B8 Contains the from date (17-07-2021)
=(MIN($B$8,D3)-MAX($A$8,C3)+1)*C5+(MIN($B$8,F3)-MAX($A$8,E3)+1)*E5+(MIN($B$8,H3)-MAX($A$8,G3)+1)*G5+(MIN($B$8,J3)-MAX($A$8,I3)+1)*I5
This will consider a period from 10-06 - 11-06 a period of 2 days. And also 12-06 - 25-06 a period of 14 days, and so on.
The result is: 2514.00
One method would be to create a lookup table and use a formula.
Given your data, your lookup table might as shown below:
I NAME'd it: priceTable
You can then use the formula:
=SUM(VLOOKUP(SEQUENCE(End-Start+1,,Start,1),priceTable,2))
If, for some reason, you cannot easily create priceTable, you can create it with a formula (depending on your version of Excel):
=INDEX($C$4:$I$6,{1,3},{1;3;5;7})
Note: All of the formulas assume your dates are real dates and not strings.
If your version of Excel does not have the SEQUENCE function, you can replace it with:
=SUM(VLOOKUP(ROW(INDEX($A:$A,Start):INDEX($A:$A,End)),priceTable,2))
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
Any idea how to simplify this equation? Criteria for each region (APAC, LATAM, EMEA, North America) varies (hour/day cut offs).
Believe it or not, this used to be longer. Here is my best attempt:
Broken out by groupings:
=IF(A2="","",
IF(WEEKDAY(B2,2)=6,"Weekend Case",
IF(AND(C2<>"APAC",WEEKDAY(B2,2)=7),"WeekendCase",
IF(AND(C2="APAC",OR(AND(WEEKDAY(B2,2)=5,HOUR(B2)>=3),AND(WEEKDAY(B2,2)=7,
HOUR(B2)<18))),"Weekend Case",
IF(AND(C2="North America",OR(AND(WEEKDAY(B2,2)=5,HOUR(B2)>=18),
AND(WEEKDAY(B2,2)=1,HOUR(B2)<8))),"Weekend Case",
IF(AND(C2="EMEA",OR(AND(WEEKDAY(B2,2)=5,HOUR(B2)>=10),
AND(WEEKDAY(B2,2)=1,HOUR(B2)<2))),"Weekend Case",
IF(AND(C2="LATAM",OR(AND(WEEKDAY(B2,2)=5,HOUR(B2)>=15),
AND(WEEKDAY(B2,2)=1,HOUR(B2)<5))),"Weekend Case",
"Weekday")))))))
Logic:
IF A2 = Nothing: Nothing
All Regions:
If Sat: WEEKEND
North America, EMEA, LATAM
IF Sun: WEEKEND
APAC:
IF Friday After 3AM OR Sunday Before 6PM: WEEKEND
North America:
IF Friday After 6PM OR Monday Before 8AM: WEEKEND
EMEA:
IF Friday After 10AM or Monday Before 2AM: WEEKEND
LATAM:
IF Friday After 3PM OR Monday Before 5AM: WEEKEND
Else:
WEEKDAY
Sample for each region with each output below:
If you can use an external table for Lookups, you should be able to simplify it (and make it easier to change should the need arise)
Lookup table:
The numbers are the number of days to offset for the Monday (col I) and the Friday (col J). i.e. for APAC, + 6 hours is =6/24 days and +21 hours is =21/24 days. (Make sure to use formulas for this table and not the numbers that appear as those are rounded)
You can then use the following formula:
=IF(AND(WEEKDAY(B2+VLOOKUP(C2,H$2:J$5,2))>=1,WEEKDAY(B2+VLOOKUP(C2,H$2:J$5,3))<=5),"Weekday","Weekend Case")
I get the same results with it as your sample.
Create a reference sheet called Schedule, and load it as follows:
A B C
1 Region WE-start WE-end
2 APAC 503 718
3 EMEA 505 802
4 LATAM 515 805
5 North America 518 818
The format of the WE values are dhh where d=weekday and hh=hour. If weekday is a Sunday, I force it to an 8 to make the calculation that follows easier.
The following formula generates your Type and corrects the EMEA one.
=IF(AND(IF(WEEKDAY(B2)=1,700,0)+WEEKDAY(B2)*100+HOUR(B2)>=VLOOKUP(C2,Schedule!$A$2:$C$5,2), IF(WEEKDAY(B2)=1,700,0)+WEEKDAY(B2)*100+HOUR(B2)<VLOOKUP(C2,Schedule!$A$2:$C$5,3)),"Weekend Case","Weekday")
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.
I have only three editable fields:
salary = 15,000
start date = 18 Jul 2014
end date = 12 Oct 2014
With these fields, I need to calculate the total salary I need to pay. Payment is on a monthly basis:
(JULY = 15,000 / 31 * 14) +
(AUG = 15,000 / 31 * 31) +
(SEPT = 15,000 / 30 * 30) +
(OCT = 15,000 / 30 * 12).
I can get total days based on both dates (ie 87 days, =DAYS($enddate,$startdate)+1) ) but I need to split the days according to the months.
What formula do I need automatically to get the amount, because each person will have different salary and different dates?
You can use Excel VBA custom Function to solve your problem:
1). First, you should populate Excel Worksheet with data structure reflecting Employees Name, Monthly Salary, StartDate and EndDate, like in the following sample:
Employee M.Salary Start Date EndDate
John $15,000.00 7/18/2014 10/12/2014
Ann $20,000.00 7/19/2014 10/13/2014
Peter $16,000.00 7/20/2014 10/14/2014
Jeff $25,000.00 7/21/2014 10/15/2014
2). The DAYS in date range can be simply found by subtraction (EndDate-StartDate), because the underlying data type in integer
3). For general solution to the problem (Calculate the compensation for any arbitrary period and monthly salary) you will need to create custom VBA formula and use it in a separate column for each Employee. Refer to this article for explanation: Create a custom worksheet function in Excel VBA
4). Pertinent to your particular case with fixed date rage, the simplified solution based on the Excel Worksheet formulas (no VBA) is described below:
Employee MoSalary Start End Days FullMo FirstMo LastMo Total
John $15,000.00 7/18/2014 10/12/2014 87 30000.00 $6,774.19 $6,000.00 $42,774.19
Ann $20,000.00 7/18/2014 10/12/2014 87 40000.00 $9,032.26 $8,000.00 $57,032.26
Peter $16,000.00 7/18/2014 10/12/2014 87 32000.00 $7,225.81 $6,400.00 $45,625.81
Jeff $25,000.00 7/18/2014 10/12/2014 87 50000.00 $11,290.32 $10,000.00 $71,290.32
4a). In column E starting with row 2 add formula for DAYS : =(D2-C2)+1 and extend it for entire range
4b). In column F starting with row 2 add formula for whole months : =2*B2 and extend it for entire range
4c). In column G starting with row 2 add formula for the first month : =14*B2/31 and extend it for entire range
4d). In column H starting with row 2 add formula for last month : =12*B2/30 and extend it for entire range
4e). In column I starting with row 2 add formula for total compensation : =SUM(F2:H2) and extend it for entire range
Hope this will help. Best regards,
I have split this out because I am not entirely sure what you require and you may be able to assemble the pieces in a way that better suits you:
Assuming your data is in A1:A3, put 1/7/14 in C1, 1/8/14 in D1, 1/9/14 in E1 and 1/10/14 in F1.
To count the number of applicable days by month, in C2 enter:
=IF(MONTH($A2)=MONTH(C1),EOMONTH(C1,0)-$A2+1,IF(MONTH($A3)=MONTH(C1),DAY($A3),EOMONTH(C1,0)-EOMONTH(C1,-1)))
To compute the salary for the month by computing the daily rate for the applicable month and multiplying that by the number of days from above, in C3 enter:
=$A1*C2/(DAYS(EOMONTH(C1,0),C1)+1)
Format C2:C3 to suit and copy across to F2:F3.