SUMPRODUCT with AND criteria on Google Sheet - google-sheets

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

Related

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

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

google sheets query filter by datediff is this possible?

So i use the following formula:
query(OVERVIEW!$B$11:$W;"Select B,C,D,I,G,H,K where month(C)="&0+$D$11&"and W matches '"&IF($B$10=TRUE;"CREATE PO";"")&"' Order by "&$B$3&"")
and what it does it checks in which month you are looking and based on the forecast it will check a couple of months and return the result in the table.
So for this example, lets say I have 12 monthly tables
Jan Feb Mar Apr Mei Jun Jul Aug Sep Okt Nov Dec
I want data to be filled under each table + forecast of 3 months
So in Jan, I get Mar orders for example. this works as it is now but if go to let's say
Okt it should give me 3 months later data so in Jan next year only the formula I have does it for this year only and if I remove the year part I get both years Jan and that is not what I want. it should count furter so Dec 2021 + 3 months will be Marth 2022.
Any pointers?
I was thinking something with Datediff en EOMONTH() functions??
Example what needs to be
UPDATE: Link to file:https://docs.google.com/spreadsheets/d/1ti7TdF2mWEGxA1E4FIeNJ7sEEtYTgu4UQtMxYqS7ets/edit?usp=sharing
Update I have created a working example in the second tab with the
following formula:
=IFERROR(QUERY(C4:C22,"select * where C >= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1-1)+1),"yyyy-mm-dd")&"'and C <= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1)),"yyyy-mm-dd")&"'"))
i do not know if this is the best solution but it works XD
=IFERROR(QUERY(C4:C22,"select * where C >= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1-1)+1),"yyyy-mm-dd")&"'and C <= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1)),"yyyy-mm-dd")&"'"))
pasting the above code in each colum and change the month to the same month you need for example Feb is "01-02"

Set Google Sheets background color by alternating weeks

I maintain a Google Sheets based release calendar for my website, where we publish new content 5 days a week (sometimes 4, sometimes 6 or 7).
In order to make viewing the release calendar easier for my team I go through and manually stripe every other week a different color. Starting with Monday, ending on Sunday. I'd like to create a formula which will do this for me, so that I can save a bit of time. Given the dates below I've indicated what color I'd like a row to be. Could someone tell me if this is possible, and if so provide some pointers as to how to accomplish it?
Mon, January 4, 2021 <-- light grey
Tue, January 5, 2021 <-- light grey
Wed, January 6, 2021 <-- light grey
Thu, January 7, 2021 <-- light grey
Fri, January 8, 2021 <-- light grey
Mon, January 11, 2021 <-- default color
Tue, January 12, 2021 <-- default color
Wed, January 13, 2021 <-- default color
Thu, January 14, 2021 <-- default color
Thu, January 14, 2021 <-- default color
Fri, January 15, 2021 <-- default color
Mon, January 18, 2021 <-- light grey
Tue, January 19, 2021 <-- light grey
Tue, January 19, 2021 <-- light grey
Wed, January 20, 2021 <-- light grey
Thu, January 21, 2021 <-- light grey
Fri, January 22, 2021 <-- light grey
Sat, January 23, 2021 <-- light grey
use in CF:
=ISEVEN(WEEKNUM(A1, 2))

I dont get the expenses of the 31 of the previous months with Activerecord in rails

When I show the total expend of PUQ theres no problem
Expend.where(cc: "PUQ").sum(:total)
But when I want to show by month individually with this code, I Don't get the expenses of the 31, only show 1 to 30 of the month. Right now I dont get the expenses of 31-08-2020
Expend.where(cc: "PUQ").where(:created_at => ((Date.today.beginning_of_month)- 1.month)..((Date.today.end_of_month) - 1.month)).sum(:total)
Thanks in advance
You can use these handy Rails methods
range = Time.current.advance(months: -1).all_month
# => Sat, 01 Aug 2020 00:00:00 UTC +00:00..Mon, 31 Aug 2020 23:59:59 UTC +00:00
Expend.where(created_at: range)
More about all_month
and about advance

Iterating months using ruby

I have a very weird requirement where I need to deal with months. Here is what I am try to do actually. I have two object say
jan_start_date=Time.parse("2012-01-01 00:00:00")
jan_end_date=Time.parse("2012-01-31 23:59:59")
I take this two datetime objects and iterate over feb, mar, april and soon to get some data.
Then I will take feb start and end dates and iterate over march, april and soon.
Its like month on month data collection. Once I am done with say Jan data, I need to take Feb's data and so on and so forth. How do I achieve this. Since I need to iterate over months.
Kindly help me out
Thanks
ActiveSupport has beginning_of_month and end_of_month:
d = Date.today
#=> Fri, 13 Jul 2012
d.beginning_of_month
#=> Sun, 01 Jul 2012
d.end_of_month
#=> Tue, 31 Jul 2012
You can use Date#>> to shift dates forward monthwise:
(d>>2).end_of_month
#=> Sun, 30 Sep 2012
(d>>4).beginning_of_month
#=> Thu, 01 Nov 2012

Resources