Calculate cumulate average values using a Google sheet/excel calculated field - google-sheets

I'm trying to find a way to aggregate average values in a Google sheet in a pivot table using calculated fields.
Here's my data:
Close Date
Amount
March 2020
£60,000.00
April 2020
£15,000.00
April 2020
£90,000.00
April 2020
£220,000.00
April 2020
£50,000.00
May 2020
£100,000.00
May 2020
£440,000.00
May 2020
£15,999.00
May 2020
£85,000.00
May 2020
£500,000.00
June 2020
£270,000.00
June 2020
£210,000.00
July 2020
£60,000.00
July 2020
£35,000.00
July 2020
£75,000.00
By using the following calculated field, I can calculated each month's average:
=AVERAGEIFS(B2:B17,A2:A17,">="&Date,A2:A17,"<="&EOMONTH(Date,0))
Close Date
Average Result
March 2020
£60,000.00
April 2020
£93,750.00
May 2020
£228,000.00
June 2020
£240,000.00
July 2020
£56,666.67
However, what I want to do is cumulate the average values like so:
Close Date
Cumulated Average Result
March 2020
£60,000.00
April 2020
£153,750.00
May 2020
£381,750.00
June 2020
£621,750.00
July 2020
£678,416.67
I realise I could add an additional formula column in the sheet itself, but I'd much prefer to do this via a calculated field if possible.
Many Thanks

Since you have tagged both Excel and Sheets, the solution in Excel is to merely select to show the values of the Average column as a Running total (in the Value Field Settings tab).

cumulative running average:
=ARRAYFORMULA({UNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "mmmm e")), MMULT(TRANSPOSE((
SEQUENCE( COUNTUNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "e-m")))<=
SEQUENCE(1, COUNTUNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "e-m"))))*
QUERY({TEXT(A1:A, "e-m"), B1:B},
"select avg(Col2) where Col2 is not null group by Col1 label avg(Col2)''")),
SEQUENCE( COUNTUNIQUE(TEXT(FILTER(A1:A, A1:A<>""), "e-m")), 1, 1, 0))})

Related

Google sheets formula to sumif within other sheets in the workbook, without writing out the sheet name, instead using reference/contents column?

I have a googlesheet (sheet 1) which looks like this:
contents contains a column with Months
May 2021
June 2021
July 2021
August 2021
September 2021
October 2021
November 2021
December 2021
January 2022
February 2022
March 2022
April 2022
May 2022
June 2022
Each month / cell in column A (sheet 1) all link to another sheet within the workbook containing the data for each month, all data has different rows, so to summarise each month, I want a formula like this:
=sumif(indirect(A4,&"!A:A"),"ProductA",(indirect(A&"!B:B")))
where A4 references January 2021, and this is linked to sheet January 2021, ProductA is in column A of each monthly breakdown (all sheets after sheet 1), and the number of these in column B.
I want to be able to drag this formula down, and have the sheet look for the sum of ProductA across all months, using Column A in sheet 1 to reference the sheet it should look in, i.e. the month.
Does this make any sense?
I can add more info, apologies for the waffle.
Sheet 2 for example contains Month1 data and looks like this:
Category (Ticket) Count Thread Time
prod1 5 22 8395:35:00
prod2 67 5411 644:24:00
prod3 544 55 18283:24:00
prod4 56 546546 97093:52:00
prod5 75 646 38238:11:00
Here is a formula that should work for you:
=arrayformula(sumif(indirect($A2&"!A:A"),C$1,(indirect($A2&"!B:B"))))
You can place this into cell C2, and then copy it down and across.
The issue with your formula was first that you had (indirect(A&"!B:B")), instead of (indirect(A2&"!B:B")).
Secondly, you need to make sure that there's no extra space after your values.
In the above image, you have an extra space after prod3, so when using the SUMIF and trying to match the value, it was not working. If something is resulting in 0 where it shouldn't be, make sure to check that first. I have found that prod4 and prod6 both have the same issue.

Google Sheets formula to convert FROM ordinal dates TO standard dates

I am looking for a formula that will automatically convert a column of ordinal date/time values into standard date/time values.
July 1st 2022 6:48:49 pm
July 2nd 2022 10:03:35 am
July 3rd 2022 5:41:12 pm
July 4th 2022 2:44:13 pm
I need to get those reformatted to eliminate the st, nd, rd, and th portions.
Sheet
You can use
=INDEX(IF(A2:A7="",, REGEXREPLACE(A2:A7,"st|nd|rd|th","")*1))
You can then format as you like
(Do adjust the formula according to your ranges and locale)
Functions used:
INDEX
IF
REGEXREPLACE

How to get days between two dates in google sheet

I have been trying to get the number of days between two dates in google-sheet but sometimes it gives an integer and sometimes it gives another date. How to get only the integer?
Shared public sheet (sheet name DS):
https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=517697699
Example
SN COMPANY AppliedDate DaysSince Today
-----------------------------------------------------------
2 McDonald Feb 17, 2021 54 1
3 Nielson Feb 17, 2021 Apr 20, 1900 2 **This should be number NOT date
4 Edelman Feb 17, 2021 111 3
5 Upstart Feb 19, 2021 Apr 18, 1900 1
6 Root Inc. Feb 19, 2021 Apr 18, 1900 2
Required
For the column DaysSince I would like to have only number. I want number between two dates but sometimes the same formula works sometimes does not work.
Is there any other methods to get number of days between two dates?
Go Format > Number > Number to format you entire column. Your problem is that your format is set as Automatic.

SUMPRODUCT with AND criteria on Google Sheet

I'm trying to count all apples, oranges and mango of a specific month and year, but the formula doesn't work right now. Is there anything obvious that I'm doing wrong here?
=SUMPRODUCT(--(TEXT(A:A,"MMYYYY")="052020"), --(B:B={"apple","orange","mango"}))
Link to the sample sheet
Colum A Column B
May 2020 apple
May 2020 apple
May 2020 banana
May 2020 orange
May 2020 mango
Jun 2020 papaya
Jun 2020 mango
Aug 2020 apple
Oct 2020 apple
Oct 2020 orange
Oct 2020 banana
try:
=COUNTA(IFNA(QUERY(B7:C,
"select B
where month(B)+1 = 5
and year(B) = 2020
and C matches 'banana|mango|apple'"))
or:
=COUNTA(IFNA(FILTER(B7:B,
TEXT(B7:B, "mmyyyy")="052020",
REGEXMATCH(C7:C, "banana|mango|apple"))
I found it :)
=SUMPRODUCT( (TEXT(B9:B19,"MMYYYY")="052020")* ISNUMBER(MATCH(C9:C19,
{"apple","orange","mango"},0)))

Duplicate column via adding a new row in Google Sheets

What formula can I use in Google Sheets to achieve this?
December 26, 2018
December 24, 2018
to
December 26, 2018
December 26, 2018
December 24, 2018
December 24, 2018
try like this:
=ARRAYFORMULA(TRANSPOSE(TEXT(TO_DATE(SPLIT(QUERY(REPT(
TO_TEXT(INDIRECT("A1:A"&COUNTA(A1:A))&"♠"), 2), , 999^99), "♠")), "mmmm dd, yyyy")))

Resources