Equation Simplification - excel

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")

Related

how to calculate the date from the year, week-of-year and day-of-week in EXCEL?

I have the Year, Week-of-Year and Day-of-the-Week as follows:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
and I would like to estimate the Date as dd.mm.yyyy, which is highlighted in yellow as it shows in the EXCEL picture.
I tried many formulas, but I am sure there might be an easy one.
I think you are counting the weeks starting from zero because for 9/1/2022 (YYYY/MM/DD format) the corresponding week is 36 as per the result of function WEEKNUM(DATE(2022,9,1)). In order to use the logic to multiply the number of weeks by 7. You need to use as a reference the first day of the year, if it was a Sunday, if not then go back to the previous Sunday, so you can count the entire week. Bottom line use as a reference date, the Sunday of the first week of the year, not the first day of the year (YYYY/1/1)
Here is the approach we use in cell E2:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1))
We use the LET function to avoid repeating the same calculation. The following expression finds the previous Sunday if the first day of the year (fDay) was not a Sunday:
fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2))
The XLOOKUP function is used to get the numeric representation of the weekday and use the TEXT function to generate the weekdays in a long format. Since we count the entire week, if the weekday is a Sunday (column C in my screenshot), then we don't need to add any day to our reference date, that is why we use seq-1.
Here is the output for several sample data. Assuming the week count starts with zero, if not the formula needs to be adjusted as also the input data.
Notice that the year 2021 started on a Friday, so if we want to find a day for the first week (0) before Friday it will return a date from the previous year. Like in the case of Monday. If you want an error message instead, then the formula can be modified as follow:
=LET(y, A2:A6, wk, B2:B6, wDay, C2:C6, fDay, DATE(y,1,1), seq, SEQUENCE(7),
result, fDay - IF(WEEKDAY(fDay)=1,0, WEEKDAY(fDay,2)) + 7*wk
+ XLOOKUP(wDay, TEXT(seq,"dddd"), seq-1),
IF(YEAR(result) <> y, "ERROR: Date from previous year", result))
I found the solution:
Year = 2022 (A2) ; Week Year = 35 (B2); Week Day = 4 or Thursday (C2)
=DATE (A2,1,3)-WEEKDAY(DATE(A2,1,3)) + 7 * B2 + C2 - 6
I found this solution, but you need to do further testing if it really works.
I calculate month from week: =+MONTH(DATE(YEAR(A2);1;1)+B2*7-1)
I calculate week day number from week day name: =MATCH(D2;{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"};0)
And then make date using: =DATE(A2;C2;E2)

Reference table and match date public holiday

I have a table that looks like this (named range PubHols):
Holiday 2018 2019 2020 2021
New Year's Day 01/01/2018 01/01/2019 01/01/2020 01/01/2021
Australia Day 26/01/2018 28/01/2019 27/01/2020 26/01/2021
Good Friday 30/03/2018 19/04/2019 10/04/2020 02/04/2021
Holy Saturday 31/03/2018 20/04/2019 11/04/2020 03/04/2021
Easter Sunday 01/04/2018 21/04/2019 12/04/2020 04/04/2021
Easter Monday 02/04/2018 22/04/2019 13/04/2020 05/04/2021
ANZAC Day 25/04/2018 25/04/2019 25/04/2020 25/04/2021
Queen's Birthday 11/06/2018 10/06/2019 08/06/2020 14/06/2021
Labour Day 01/10/2018 07/10/2019 05/10/2020 04/10/2021
Christmas Day 25/12/2018 25/12/2019 25/12/2020 25/12/2021
Boxing Day 26/12/2018 26/12/2019 26/12/2020 26/12/2021
Trying to incorporate into a function - that is to check if the date is a public holiday first, and then run the ifs.
Current formula is:
=IF($A2="","",IFS(WEEKDAY($A2)=1,"Sun",WEEKDAY($A2)=2,"Weekday",WEEKDAY($A2)=3,"Weekday",WEEKDAY($A2)=4,"Weekday",WEEKDAY($A2)=5,"Weekday",WEEKDAY($A2)=6,"Weekday",WEEKDAY($A2)=7,"Saturday"))
You could put the test for a public holiday into your existing formula like this:
=IFS($A$2="","",COUNTIF(PubHols,A2),"Public Holiday",WEEKDAY($A2)=1,"Sun",WEEKDAY($A2)=2,"Weekday",WEEKDAY($A2)=3,"Weekday",WEEKDAY($A2)=4,"Weekday",WEEKDAY($A2)=5,"Weekday",WEEKDAY($A2)=6,"Weekday",WEEKDAY($A2)=7,"Saturday")
But there are much shorter ways of testing if a date is a working day, e.g. the one described here
=WORKDAY(A2-1,1,PubHols)=A2
So if you wanted to tell if the day was a working day, public holiday, Saturday or Sunday you could use:
=IFS(A2="","",WORKDAY(A2-1,1,PubHols)=A2,"Working Day",WEEKDAY(A2)=1,"Sun",WEEKDAY(A2)=7,"Sat",TRUE,"Public holiday")
It's interesting that the two formulas give different results. I think the reason is that a public holiday should never fall on a weekend, so probably Monday 28th December will be a public holiday this year rather than Saturday 26th.

How to count days excluding weekends and holidays but start day/end day can be weekends /holidays?

How to count days excluding weekends and holidays in excel. However, start day and end day can be weekends or holidays.
I have tried Networkdays function in excel using MAC. I also tried workdays function. And, i am new to this forum. Let me know if you are not able to understand anything.
Start Date(E) End Date (F)
2019-07-20 - 2019-08-01
2019-08-04 - 2019-08-06
2019-08-05 - 2019-08-07
2019-08-02 - 2019-08-07
2019-08-14 - 2019-08-20
Holiday list
Date(K) Description Day
8/12/19 - Eid - Monday
8/15/19 - Independence Day - Thursday
Excel formula:
= NETWORKDAYS(E2,F2,$K$7:$K$27)
Start date: Column E, End date: Column F, Holiday list: Column H
output expected output
9 8
2 1
3 1
4 2
4 2
Try using NETWORKDAYS.INTL to make sure that your weekend days are set to fall on Saturdays and Sundays.
For example:
=NETWORKDAYS.INTL(E2+1,F2-1,1,$H$2:$H$3)
Result:

Excel Formula to get Season name?

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"})

Excel lookup same index different row

I have a formatted table that contains information about areas, including sales for the month (and a heap of other columns containing other details). The table is the basis for graphs and pivot tables.
There is a row per month for each area, e.g.:
A B C D
1 Area Month Sales TwoMonthAverage
2 North 1 400 Manually entered
3 West 1 500 Manually entered
4 South 1 200 Manually entered
5 North 2 200 <calculate??>
6 West 2 200 <calculate??>
7 South 2 200 <calculate??>
8 North 3 100 <calculate??>
9 West 3 900 <calculate??>
10 South 3 600 <calculate??>
Each month, I want to calculate the "2 month average" sales for an area (being the average of the current and previous months).
I need to know how to get the sales for the same area for the previous month. The table rows will not necessarily be in the same area or month order. Needs to work in Excel 2013 and 2010.
Thanks
Blair
You could perhaps use SUMIFS to get the sum of the past 2 months sale:
=SUMIFS($C$2:C5, $A$2:A5, A5, $B$2:B5, ">="&B5-1)
This in D5 will give the sum of values that:
Have values in cells A above and including the current row, and
Have the month above or equal to the current month - 1.
You then only need to divide by 2 to get the 2 month average.

Resources