Compile on column with name as year - calculated-columns

I have a data with column names 2020, 2019
then I have in a variable refYear the value 2020
dataFr <- data.table(`2020`=c(120,110),
`2019`= c(105,98))
I want to compile change from 2019 to 2020 using
refyear-as.character(as.numeric(refYear)-1) / as.character(as.numeric(refYear)-1)
How can I write this? (dplyr)

Related

How to grab the running total of the first day of the month?

I'm trying to write an Excel function to grab the value of the Running Total in rows that are on the first of the month in the Date column. Where there are more rows with the same date, I want to grab the last value. (The dates are in ascending order.)
This is an example of the kind of table I'm using:
Income
Running Total
Date
$1,000.00
$1,000.00
Jun 30, 22
-$60.00
$940.00
Jul 01, 22
-$42.00
$898.00
Jul 20, 22
-$55.00
$843.00
Aug 01, 22
-$200.00
$643.00
Aug 01, 22
-$60.00
$583.00
Aug 19, 22
-$20.00
$563.00
Sep 01, 22
$334.00
$897.00
Sep 10, 22
-$610.00
$287.00
Oct 01, 22
-$50.00
$237.00
Oct 02, 22
I have a formula for calculating the running total and the date is created with the DATE() function.
I'm planing to use the function in a new table on the same sheet. In each row is the running total of the first of that month.
Month
Amount
Jul
Aug
Sep
Oct
The problem is that I'm expecting this table to grow and I don't want to manually search each row. I would like to have a function that goes through the Date column and identifies if it contains the date of the first day of the month, if it does, get the running total.
I have attempted something like this:
=CONCAT("$B",MATCH(”Jul 01, 22”,$C1:$C100,1))
But I don't know how to create the function or whether or not this works.
How can I write a function that grabs the Running Total on the first of the month?
You can use either INDEX() & MATCH() or XLOOKUP()
• Formula used in cell F2
=INDEX($B$2:$B$11,MATCH(DATE(2022,MONTH(E2&1),1),$C$2:$C$11,1))
Or,
• Formula used in cell H2
=XLOOKUP(DATE(2022,MONTH(E2:E5&1),1),C2:C11,B2:B11,,1,-1)
or, can exclude the 5th parameter, of XLOOKUP() as well
• Formula used in cell H2
=XLOOKUP(DATE(2022,MONTH(E2:E5&1),1),C2:C11,B2:B11,,,-1)

How to use python3 to read some specific columns of .xlsx files, sort them by time and put them into new row?

I have a .xlsx data likes this.
NAME a b c ...
2012 1246108359 190153864 NA ...
2013 1089521299 181339787 -122350575 ...
2015 2092545545 648831005 -69981000 ...
2014 802730996 435162019 -69644809 ...
2017 1681536957 690355938 -1210327000 ...
2016 1149898973 491972036 -226538000 ...
First, I want to extract every column and sort them by time.
And then, put them into a new row.
How can I do this?
It shall be like this.
2012 a 1246108359
2013 a 1089521299
2014 a 802730996
2015 a 2092545545
2016 a 1149898973
2017 a 1681536957
2012 b 190153864
2013 b 181339787
2014 b 435162019
2015 b 648831005
2016 b 491972036
2017 b 690355938
... ... ...
you can use melt to do this
firs sort values
df.sort_values('NAME', inplace=True)
df.melt(id_vars='NAME', value_vars=df.columns[1:])
you can use the params value_name and var_name to change the column names

Excel: Value from one cell based on max value with multiple criteria in other column

I am trying to get value in column 8, based on MAX value (column Range4) with multiple criteria (Range1, Range2, Range3), but excel gives me an error "#N/A". Where is the mistake?
VLOOKUP(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));Range5;8;FALSE)
The part
{MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))))}
works right alone (it gives me the right value), but not inside the VLOOKUP function.
Thanks!
Sample data set for testing:
First_day Last_day Week_Num Week_Range Month Year Rank_name Rank_value
01/04/2013 07/04/2013 14 1-7 april april 2013 Alexa 10122
08/04/2013 14/04/2013 15 8-14 april april 2013 Alexa 9670
15/04/2013 21/04/2013 16 15-21 april april 2013 Alexa 9130
22/04/2013 28/04/2013 17 22-28 april april 2013 Alexa 8340
29/04/2013 05/05/2013 18 29-5 april april 2013 Alexa 7543
31/03/2014 06/04/2014 14 31-06 april april 2014 Alexa 11428
07/04/2014 13/04/2014 15 07-13 april april 2014 Alexa 7159
14/04/2014 20/04/2014 16 14-20 april april 2014 Alexa 7027
21/04/2014 27/04/2014 17 21-27 april april 2014 Alexa 6675
28/04/2014 04/05/2014 18 28-04 april april 2014 Alexa 5379
Equivalence between ranges and columns:
Range1 = Column "Year"
Range2 = Column "Month"
Range3 = Column "Rank_name"
Range4 = Column "Week_Num"
Range5 = Column "Rank_value"
Please try:
=INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));Range4;0))
with Control+Shift+Enter.
The problem with the existing formula (from pnuts, Jun 10 2014) is this:
The formula first narrows the list down by the nested if's, and then picks the maximum Week_Num from those rows that match your criteria. But having located that maximum, the MATCH function then ignores the criteria (they were only used to find the max from Range4). If you have other rows (even though they don't match the criteria) that have the same Week_Num, MATCH will locate the first row out of the whole list that has the same Week_Num in Range4. One solution is to add the same criteria to the MATCH's "lookup_array" that were used in the "lookup_value".
=INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4)));0))
Again, using Control-Shift-Enter.
I think I entered the above formula correctly, but I didn't build a sheet to test it, so...
Also, be aware, this formula still has a problem in the case where no rows in the list meet the criteria. In that case you get an error. The solution to that is to add an IFERROR at the front of the whole thing.
=IFERROR(INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4)));0)),"")

Excel Doc Sum row b where row a in between dates

I have a google spreadsheet having data as below
Date SomeVal
Aug 01, 2013 1
Aug 02, 2013 5
And so on. I want to have another sheet with Monthly grouping as follows(This is what I want in the end but unable to get here)
Month Total
Apr 2013 200
May 2013 300
I tried following but could not get correct result
=SUMIFS(Sheet1!B:B,Sheet1!A:A,ʺ> Aug 1, 2013ʺ) //Returns SUM(B:B) as all dates are above Aug 1 2013
=SUMIFS(Sheet1!B:B,Sheet1!A:A,ʺ< Jun 1, 2014ʺ) //Returns 0 which is wrong
This is what I expected to get
sum for which date > Aug 2013
sum for which date < Jun 2014
My date format is Mon DD, YYYY
Any idea Where I am wrong
This format works for me
Raw Data in Sheet2
(Column A) (Column B)
Date Val
----------- ---------
7/1/2013 1
7/2/2013 2
7/3/2013 3
7/4/2013 4
And so on and so forth up until 2/9/2016 (as long as they are date values you can format them however you want)
Summed Data in Sheet1
(Column A) (Column B)
Month Total
---------- ---------
Jul 2013 496
Aug 2013 1457
Sep 2013 2325
Oct 2013 3348
Nov 2013 4155
So on and so forth for each month that I want, using this formula. Each month is formatted as MMM YYYY, and the date is the first of the month (7/1/2013, 8/1/2013, etc...)
=SUMIFS(Sheet2!$B:$B,Sheet2!$A:$A,">="&Sheet1!$A2,Sheet2!$A:$A,"<"&Sheet1!$A3)
This says
Sum the range in Sheet 2 Column B where:
The date in column A of that row is greater than the first of the month supplied
The date in column A of that row is less than the first of the month afterwards

How do i add year (date) criteria to DSUM?

I have a database that looks like this:
(A1)Client (B1) Date (C1) debts
(A2)1 (B2) Mon 2 november 2008 (C2) 1500$
(A3)2 (B3) Thu 7 february 2008 (C3) 1000$
(A4)3 (B4) Sat 28 March 2009 (C4) 800$
(A5)4 (B5) Mon 16 March 2009 (C5) 1200$
The date format is 24/11/2008.
I have to use DSUM to get the sum of the debts clients had in 2008.
I already did a table that looks like this:
(A7)Client (A7) Date (C7) debts
(A9) 2008
and the function =DSUM(A1:C5,3,A7:C8) but it seems I can't extract the value of 2008 from the date 24/11/2008.
It is generally not a good idea to store dates as text, change your 2008 to 1/1/2008 and format as "YYYY"
To use DSUM to sum entries that fall in a calendar year you will have to define the start and end date, so your filter data will look like this:
Client Date Date
debts =">=1/1/2008" ="<1/1/2009"

Resources