Excel Formula to get Accounting Day like Day 0, Day 1, Day 2 till Day 5 Excluding Weekends - excel

Date Status LastWorkingDate
7/3/2017 Day 0 7/3/2017
7/1/2017 Day 1 7/3/2017
7/2/2017 Day 1 7/3/2017
6/30/2017 Day 1 7/3/2017
6/29/2017 Day 2 7/3/2017
6/28/2017 Day 3 7/3/2017
6/27/2017 Day 4 7/3/2017
6/26/2017 Day 5 7/3/2017
6/25/2017 Day 6 7/3/2017
6/24/2017 Day 6 7/3/2017
6/23/2017 Day 6 7/3/2017
6/22/2017 More than Day 6 7/3/2017
7/4/2017 Day 0 7/4/2017
7/3/2017 Day 1 7/4/2017
7/2/2017 Day 2 7/4/2017
7/1/2017 Day 2 7/4/2017
6/30/2017 Day 2 7/4/2017
6/29/2017 Day 3 7/4/2017
6/28/2017 Day 4 7/4/2017
6/27/2017 Day 5 7/4/2017
6/26/2017 Day 6 7/4/2017
6/25/2017 More than Day 6 7/4/2017
i have tried using =
IF(NETWORKDAYS(E21,G21)-1=0,"day 0",IF(NETWORKDAYS(E21,G21)-1=1,"Day 1",IF(NETWORKDAYS(E21,G21)-1=2,"Day 2",IF(NETWORKDAYS(E21,G21)-1=3,"Day 3",IF(NETWORKDAYS(E21,G21)-1=4,"Day 4",IF(NETWORKDAYS(E21,G21)-1=5,"Day 5","Greater than 5 Days"))))))
but not getting desired output.
All i want is Day 0 to Day 5 based on two date columns(Date and LAstWorkingDate).
Day 0 = if today is monday then lastworkingdate will be friday and friday, Sat and Sunday will become Day 0 and previous week's thursday will be Day 1 and so on
Day 1 = if today is Tuesday then Lastworking Date will be Monday and Monday will become Day 0, Friday,Sat and Sunday will be Day 1 and so on
Day 2 = if today is wednesday ten Lastworkind Date will be Tuesday and Tuesday will become Day 0, Monday - Day 1, Friday, Sat and Sunday wull be Day 2 and so on
.
.
.

How about:
="Day "&(NETWORKDAYS(IF(WEEKDAY(A1,2)=7,A1-2,IF(WEEKDAY(A1,2)=6,A1-1,A1)),C1)-1)
Using your current layout for Last Working Day and Date.
The weekday functions are needed because otherwise the Saturday and Sunday would get the same value as Monday instead of Friday.
Of course you can wrap the whole thing in an IF-formula to make sure you display "Greater than 5 days" when the value is bigger than 5.
Output:
Date | Formula column | Last working day
--------------------------------------------
6/17/2017| Day 11 | 7/3/2017 'Weekend
6/18/2017| Day 11 | 7/3/2017 'Weekend
6/19/2017| Day 10 | 7/3/2017
6/20/2017| Day 9 | 7/3/2017
6/21/2017| Day 8 | 7/3/2017
6/22/2017| Day 7 | 7/3/2017
6/23/2017| Day 6 | 7/3/2017
6/24/2017| Day 6 | 7/3/2017 'Weekend
6/25/2017| Day 6 | 7/3/2017 'Weekend
6/26/2017| Day 5 | 7/3/2017
6/27/2017| Day 4 | 7/3/2017
6/28/2017| Day 3 | 7/3/2017
6/29/2017| Day 2 | 7/3/2017
6/30/2017| Day 1 | 7/3/2017
7/1/2017 | Day 1 | 7/3/2017 'Weekend
7/2/2017 | Day 1 | 7/3/2017 'Weekend
7/3/2017 | Day 0 | 7/3/2017

Related

Can i use TextSplit with Find formula?

I am making a table up that will sum all matches of a company found within a specific time period. I need to also exclude certain months if they are inserted into a cell as mm/yy. Excluding one month is fine but when i type 10/22, 11/22, it will sum everthing. THe below code is what i am using with U$4 being the end of a month minus the tracking period which is 90 days. Note that the Raw Data that it is reading from only goes to end of November.
=IF([#[Company Name]]="","",SUM(IF(ISNUMBER(SEARCH([#[Company Name]],RawData[Description]))=TRUE,IF(RawData[Home]=XLOOKUP($D$1,HomeList[Home Code],HomeList[Home]),IF(RawData[Source]="Spend Money",IF(RawData[Date]<=U$4,IF(RawData[Date]>=U$4-[#[Tracking period (Days)]],1,0)))))))
With one date inserted which is correct:
28/Feb 31/Mar 30/Apr 31/May 30/Jun 31/Jul 31/Aug 30/Sep 31/Oct 30/Nov 31/Dec 31/Jan
Exclude Company Name Tracking period (Days) Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 Month 7 Month 8 Month 9 Month 10 Month 11 Month 12
11/22 CLH 90 0 0 0 0 0 0 0 1 2 2 1 0
With multiple months inserted which is incorrect:
28/Feb 31/Mar 30/Apr 31/May 30/Jun 31/Jul 31/Aug 30/Sep 31/Oct 30/Nov 31/Dec 31/Jan
Exclude Company Name Tracking period (Days) Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 Month 7 Month 8 Month 9 Month 10 Month 11 Month 12
10/22,11/22 CLH 90 0 0 0 0 0 0 0 2 3 8 6 5
Expected if multiple months as it has found one match for September so counts it
28/Feb 31/Mar 30/Apr 31/May 30/Jun 31/Jul 31/Aug 30/Sep 31/Oct 30/Nov 31/Dec 31/Jan
Exclude Company Name Tracking period (Days) Month 1 Month 2 Month 3 Month 4 Month 5 Month 6 Month 7 Month 8 Month 9 Month 10 Month 11 Month 12
10/22,11/22 CLH 90 0 0 0 0 0 0 0 1 1 1 0 0
Had to use MATCH with the TEXTSPLIT for it to work
=IF([#[Company Name]]="","",SUM(IF(ISNUMBER(SEARCH([#[Company Name]],RawData[Description]))=TRUE,IF(RawData[Home]=XLOOKUP($D$1,HomeList[Home Code],HomeList[Home]),IF(RawData[Source]="Spend Money",IF(RawData[Date]<=S$4,IF(RawData[Date]>=S$4-[#[Tracking period (Days)]],IF(ISNUMBER(MATCH(RawData[Find Date],TEXTSPLIT([#Exclude],","),)),0,1))))))))

How to add days based on another date?

i want to add +2 days to column based on other column i use this table :
Company Type Joinning Date Starting day
1 1 19/01/2019
2 0 19/01/2019
3 0 19/01/2019
4 1 20/01/2019
5 0 20/01/2019
6 1 21/01/2019
i want to add +2 DAYS in column Starting day which is Joining day + 2 days if the company have type 1 how can i do it ?
What i've tried ?
pic
Desired Results
Company Type Joinning Date Starting day
1 1 19/01/2019 21/01/2019
2 0 19/01/2019
3 0 19/01/2019
4 1 20/01/2019 22/01/2019
5 0 20/01/2019
6 1 21/01/2019 23/01/2019
Just to show my comment of:
=IF(B2=1,C2+2,"")
Works. The output cell must be formatted in the desired method:

doing cumulative sum for each year and month in sparksql

Input:
item loc qty year month
A IND 10 2019 13
A IND 20 2020 1
A IND 10 2020 2
A IND 40 2020 3
A IND 50 2020 5
A IND 10 2020 6
OUTPUT:
item loc sum(qty) year month
A IND 0 2019 13
A IND 10 2020 1
A IND 30 2020 2
A IND 40 2020 3
A IND 50 2020 5
A IND 90 2020 6
description:
how will i get my output is as follows:
if i am calculationg for year 2020 and month 3 then i need to consider the sum(qty) between (month-3) and (month-1) i.e. in this case it will be from year 2019 month 12 to year 2020 and month 2
so for year 2020 and month 3 the ouput will be sum(qty)=10+20+10=40
now for year 2020 and month 6
sum(qty) will be between year 2020 and month -3=3 and year 2020 and month-1=5
so sum(qty)=0(0 for month 4 which is not in the table)+40+50=90
Try this.
df.createOrReplaceTempView("test")
spark.sql("""
SELECT
item,
loc,
COALESCE(
SUM(qty) OVER (
PARTITION BY item
ORDER BY (year - 2000) * 13 + month
RANGE BETWEEN 3 PRECEDING AND 1 PRECEDING
), 0) as sum_qty,
year,
month
FROM
test
""").show
+----+---+-------+----+-----+
|item|loc|sum_qty|year|month|
+----+---+-------+----+-----+
| A|IND| 0|2019| 13|
| A|IND| 10|2020| 1|
| A|IND| 30|2020| 2|
| A|IND| 40|2020| 3|
| A|IND| 50|2020| 5|
| A|IND| 90|2020| 6|
+----+---+-------+----+-----+

how to Get week number from specified year date in python?

I have a time-series data and i want to get the week number from the initial date
date
20180401
20180402
20180902
20190130
20190401
Things Tried
Code
df["date"]= pd.to_datetime(df.date,format='%Y%m%d')
df["week_no"]= df.date.dt.week
But the week getting reset in 2019 results in getting a common week number of 2018.
is there anything we can do in it ??
You can use this function that will calculate the difference between two days in weeks:
def Wdiff(fromdate, todate):
d = pd.to_datetime(todate) - pd.to_datetime(fromdate)
return int(d / np.timedelta64(1, 'W'))
You can create a datetime object with the specified date, then retrieve the week number using the isocalendar method:
import datetime
myDate = datetime.date(2018, 4, 1)
week = myDate.isocalendar()[1]
print(week)
You could then calculate the total number of remaining weeks in 2018, then add the total number of weeks in each year in between, and finally add the week number of the current date.
For example, this code would print the number of weeks from the 1st of April 2018 to the 6th May 2020:
import datetime
myDate = datetime.date(2018, 4, 1)
currentDate = datetime.date(2020, 5, 6)
weeks = datetime.date(myDate.year, 12, 28).isocalendar()[1] -
myDate.isocalendar()[1]
for i in range(myDate.year, currentDate.year):
weeks += datetime.date(i, 12, 28).isocalendar()[1]
weeks += currentDate.isocalendar()[1]
print(weeks)
Note that because of the way isocalendar works, the 28th of December will always be in the last week of the given year.
The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year.
You can get more information about isocalendar here: https://docs.python.org/3/library/datetime.html
To get the week number, but as a 2-digit string (with leading zero),
you can run:
df['week_no'] = df.date.dt.strftime('%W')
The result, for slightly extended source data is:
date week_no
0 2018-04-01 13
1 2018-04-02 14
2 2018-09-02 35
3 2018-12-30 52
4 2018-12-31 53
5 2019-01-01 00
6 2019-01-02 00
7 2019-01-03 00
8 2019-01-04 00
9 2019-01-05 00
10 2019-01-06 00
11 2019-01-07 01
12 2019-01-30 04
13 2019-04-01 13
Note that the last day of 2018 (monday) has week No == 53 and "initial" days
in 2019 (up to 2019-01-06 - Sunday) have week No == 00.
If you want this column as int, append .astype(int) to the above code.

Select Data based on more than one weekday name in Python

I am trying to get data for weekday Sunday and Monday, but it only give me one day's data. I can find answer for one weekday name from a question asked by somebody.
Below are the code:
import pandas as pd
df=pd.DataFrame({'CustomerID':[1,2,3,4,5,6,7,8,9,10],
'PurchaseDate':['2007-5-7','2007-6-7','2007-7-7','2007-8-7','2007-9-9','2007-10-7',
'2007-11-7','2007-12-7','2008-1-7','2008-2-7' ],
'OrderQuantity':[1,1,1,1,1,1,1,1,1,1]})
df['PurchaseDate']=pd.to_datetime(df.PurchaseDate)
df.dtypes
df.PurchaseDate.dt.weekday_name.value_counts()
df1=df[(df.PurchaseDate.dt.weekday_name==('Sunday' and 'Monday'))]
The result I got is as in the picture below:
How would I get data for Sunday and Monday?
Use Series.isin if want weekday_name Sunday OR Monday - each date cannot be Sunday and also Monday:
df1=df[(df.PurchaseDate.dt.weekday_name.isin(['Sunday','Monday']))]
print (df1)
CustomerID PurchaseDate OrderQuantity
0 1 2007-05-07 1
4 5 2007-09-09 1
5 6 2007-10-07 1
8 9 2008-01-07 1
Verify:
print (df.PurchaseDate.dt.weekday_name)
0 Monday
1 Thursday
2 Saturday
3 Tuesday
4 Sunday
5 Sunday
6 Wednesday
7 Friday
8 Monday
9 Thursday
Name: PurchaseDate, dtype: object

Resources