I have a Values like
Month Price
Jan 10
Feb 20
Mar 30
............
Dec 50
I have a dropdown for selecting month
If user pickedup the month Feb
then the sum should be displayed as 30
Help me out ! tried a lot with excel function ended up with frustration
Very interesting idea.
Formula in B1 =SUM(INDIRECT("E1:E"&MATCH(A1,D:D,0)))
Hope this will help you.
A B C D E
Feb 30 Month Price
Jan 10
Feb 20
Mar 30
Apr 40
May 50
Jun 60
Jul 70
Aug 80
Sep 90
Oct 100
Nov 110
Dec 120
Related
I have an excel file which contain data like this:-
Prod
Work
Vaction
Year
2022
2022
2023
2022
2022
2023
2022
Month
10
11
12
10
11
12
10
Name
Business?
Exclusive?
Oct
Nov
Dec
Oct
Nov
Dec
Oct
Robert
Yes
No
100
100
100
150
150
150
1.1
Maria
No
Yes
75
75
50
25
25
25
1
and I want to convert this table into this form:
Name
Business?
Exclusive?
Year
Month
Prod
Work
Vacation
Robert
Yes
No
2022
Oct
100
150
1.1
Maria
No
Yes
2022
Nov
100
150
1
Robert
No
Yes
2023
Dec
100
150
1
Maria
No
Yes
2023
Dec
50
150
1
With the help of python pandas library. I am struggling with this problem from so many days. Please Help!
I have a dataframe which has 3 columns [user_id ,year_month & value] , i want to calculate last 6months average for the year automatically for each individual unique user_id and assign it to new column
user_id value year_month
1 50 2021-01
1 54 2021-02
.. .. ..
1 50 2021-11
1 47 2021-12
2 36 2021-01
2 48.5 2021-05
.. .. ..
2 54 2021-11
2 30.2 2021-12
3 41.4 2021-01
3 48.5 2021-02
3 41.4 2021-05
.. .. ..
3 30.2 2021-12
Total year has 12-24 months
to get jan 2022 value[dec 2021 to july 2021]=[55+32+33+63+54+51]/6
to get feb 2022 value[jan 2022 to aug 2021] =[32+33+37+53+54+51]/6
to get mar 2022 value[feb 2022 to sep 2021] =[45+32+33+63+54+51]/6
to get apr 2022 value[mar 2022 to oct 2021] =[63+54+51+45+32+33]/6
First index, your datetime column
df = df.set_index('year_month')
Then do the following
df.groupby('UserId').rolling('6M').transform('avg')
This is the most correct way but hey here is one more intutitive
df.sort_values('year_month').groupby('UserId').rolling(6).transform('avg') # Returns wanted series
As paul h said
I work on an application that uses native Unix CRON tab for scheduling jobs. the description of parameters are as follows :
Minute, Hour, Da_of_Week(1-7, 1=Sun), Day_of_Month(1-31), Day_of_Year(1-365), Week (1-52), Month (1-12)
I want to run a job on Monday of the 1st week of the year at 8 pm, but I don't know how to determine when the week starts. Is 31 Dec 2017 - 06th Jan 2018 a first week or 7th Jan to 13th Jan 2018 a first week ?
Having cron jobs running on particular week numbers is not easy
as everything depends on the definition of week numbers you are
used too.
European (ISO 8601)
This ISO 8601 standard is widely used in the world: EU and most of other
European countries, most of Asia, and Oceania
The ISO 8601 standard states the following:
There are 7 days in a week
The first day of the week is a Monday
The first week is the first week of the year which contains a
Thursday. This means it is the first week with 4 days or more
in January.
With this definition, it is possible to have a week number 53. These occur with the first of January is on a
Friday (E.g. 2016-01-01, 2010-01-01). Or, if the year before was a
leap year, also a Saturday. (E.g. 2005-01-01)
December 2015 January 2016
Mo Tu We Th Fr Sa Su CW Mo Tu We Th Fr Sa Su CW
1 2 3 4 5 6 49 1 2 3 53
7 8 9 10 11 12 13 50 4 5 6 7 8 9 10 01
14 15 16 17 18 19 20 51 11 12 13 14 15 16 17 02
21 22 23 24 25 26 27 52 18 19 20 21 22 23 24 03
28 29 30 31 53 25 26 27 28 29 30 31 04
American or Islamic (Not ISO 8601)
Not all countries use the ISO 8601 system. They use a more absolute approach.
The American system is used in Canada, United States, New Zealand, India, Japan,...
The Islamic system is generally used in the middle east.
Both systems are very similar.
American:
There are 7 days in a week
The first day of the week is a Sunday
The first week starts on the 1st of January
Islamic:
There are 7 days in a week
The first day of the week is a Saturday
The first week starts on the 1st of January
With these definitions, it is possible to have partial weeks at the
beginning and the end of a year. Hence the first and last week of the
year could not contain all weekdays.
American:
December 2015 January 2016
Su Mo Tu We Th Fr Sa CW Su Mo Tu We Th Fr Sa CW
1 2 3 4 5 49 1 2 01
6 7 8 9 10 11 12 50 3 4 5 6 7 8 9 02
13 14 15 16 17 18 19 51 10 11 12 13 14 15 16 03
20 21 22 23 24 25 26 52 17 18 19 20 21 22 23 04
27 28 29 30 31 53 24 25 26 27 28 29 30 05
31 06
Islamic:
December 2015 January 2016
Sa Su Mo Tu We Th Fr CW Sa Su Mo Tu We Th Fr CW
1 2 3 4 49 1 01
5 6 7 8 9 10 11 50 2 3 4 5 6 7 8 02
12 13 14 15 16 17 18 51 9 10 11 12 13 14 15 03
19 20 21 22 23 24 25 52 16 17 18 19 20 21 22 04
26 27 28 29 30 31 53 23 24 25 26 27 28 29 05
30 31 06
Note: this could be particularly cumbersome for the task you try to
perform. Especially if it has to occur on the Monday of the first
week. This Monday might not exist.
Importing this in the cron
Adding these systems to the cron cannot be done in a direct way. The
week testing should be done by means of a conditional test of the form
weektestcmd weeknr && cmd
For a cronjob to be run only on the Monday of the 4th week of the year at 20:00 system time (as the OP requested), the crontab would look then as:
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
0 20 * * 1 weektestcmd 4 && cmd
With weektestcmd defined as
ISO 8601 week numbers:
#!/usr/bin/env bash
[[ $(date '+%V') -eq $1 ]]
American calendar week numbers:
#!/usr/bin/env bash
# obtain the day of year
doy=$(date "+%j")
# compute the week offset of the first of January
## compute the day of the week with Mo=1 .. Su=7
offset=$(date -d $(date "+%Y")-01-01 "+%u")
## Take the modulo for the offset as Su=0
offset=$(( offset%7 ))
# Compute the current week number
cw=$(( (doy + offset + 6)/7 ))
[[ $cw -eq $1 ]]
Islamic calendar week numbers:
#!/usr/bin/env bash
# obtain the day of year
doy=$(date "+%j")
# compute the week offset of the first of January
## compute the day of the week with Mo=1 .. Su=7
offset=$(date -d $(date "+%Y")-01-01 "+%u")
## Take the modulo for the offset as Sa=0
offset=$(( (offset + 1)%7 ))
# Compute the current week number
cw=$(( (doy + offset + 6)/7 ))
[[ $cw -eq $1 ]]
Note: Be aware that in the American and Islamic system it might be possible not to have a Monday in week 1.
Note: There are other methods of defining a week number. Nonetheless, the approach stays the same. Define a script which checks the week number and use it in the cron.
You have to put a condition in your crontab to do that. Your cron will look
something like this,
0 20 1-7 1 * root [ `date +%a` == "Mon" ] && /run/some/script
cron 0 20 1-7 1 * runs at 8pm everyday from 1st to 7th in the month of January.
Following checks that the day is Monday before executing your script.
[ `date +%a` == "Mon" ]
With this, script will run on the 7th January 2019, which is within the first week of the year.
$ cal 01 2019
January 2019
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
I have a source table data with the below date, week, month and year information.
CALENDAR_DATE WEEK MONTH YEAR
15-Jun-15 25 2015 / 06 2015
16-Jun-15 25 2015 / 06 2015
17-Jun-15 25 2015 / 06 2015
18-Jun-15 25 2015 / 06 2015
19-Jun-15 25 2015 / 06 2015
20-Jun-15 25 2015 / 06 2015
21-Jun-15 26 2015 / 06 2015
22-Jun-15 26 2015 / 06 2015
23-Jun-15 26 2015 / 06 2015
24-Jun-15 26 2015 / 06 2015
25-Jun-15 26 2015 / 06 2015
26-Jun-15 26 2015 / 06 2015
27-Jun-15 26 2015 / 06 2015
28-Jun-15 27 2015 / 06 2015
29-Jun-15 27 2015 / 06 2015
30-Jun-15 27 2015 / 06 2015
I am building a dependent data validation list where i need to extract all unique week numbers for each month as below
2016 2016 / 01 2016 / 02
2016 / 01 1 5
2016 / 02 2 6
2016 / 03 3 7
2016 / 04 4 8
2016 / 05
2016 / 06
2016 / 07
2016 / 08
2016 / 09
2016 / 10
2016 / 11
2016 / 12
Is there a formula with a combination of index, countif and/or vlookup that would serve the purpose. Any guidance would be super helpful
You can do it with an array formula. If you have the dates and week numbers starting in A2 and B2, and the required month number in D1,E1 etc. the formula is:-
=IFERROR(INDEX($B$2:$B$1000,MATCH(1,(COUNTIF(D$2:D2,$B$2:$B$1000)=0)*(MONTH($A$2:$A$1000)=D$1)*($A$2:$A$1000<>""),0)),"")
entered in D3 using CtrlShiftEnter
Note: there must be another approach to this which doesn't need all the week numbers to be listed - just start at the beginning of each month and step forward by 7 days each time, with a bit of logic for the end of the month.
Starting with the first of the month in G3, I came up with this formula to give the 8th, 15th etc. up to the last week of the month. Then you just need to get the WEEKNUM of each of those dates.
=IF((G3+7)>EOMONTH(G3,0),IF(WEEKNUM(EOMONTH(G3,0))>WEEKNUM(G3),EOMONTH(G3,0),""),G3+7)
I have an excel 2007 file with data of weekly values for two years. I want to collate this into a cumulative monthly sum, but also bare in mind the year. For example, If I had the following dates:
6 Apr 13
13 Apr 13
20 Apr 13
27 Apr 13
4 May 13
.
.
.
.
.
12 Apr 14
19 Apr 14
26 Apr 14
3 May 14
10 May 14
17 May 14
24 May 14
.
.
.
.
14 Feb 15
21 Feb 15
28 Feb 15
7 Mar 15
14 Mar 15
21 Mar 15
28 Mar 15
And I wanted to get the summed totals for the following periods:
April 2013
May 2013
June 2013
July 2013
.
.
.
.
April 2014
May 2014
June 2014
.
.
.
January 2015
February 2015
March 2015
What would be the best way to go about doing so? I was thinking to use Sumifs, but was uncertain how well Month() and Year() play if the function was written like sumif(...Year(...Month(..))).
Assuming your data is in Cells A1:B15, with dates in column A and qaintity to be summed in Column B, you can try this:
=SUMPRODUCT((MONTH(A1:A15)=2)*(YEAR(A1:A15)=2014)*(B1:B15))
You can replace "2" with month of your choice and 2014 with desired year. Hope that helps.