Google Sheets Formula: Sum if Substring in range of cells - google-sheets

I have two columns:
Col A Col B
01.02.2020 17
03.11.2020 24
03.11.2020 12
I tried to sum Col B, based on the substring of Col A like so:
=SUMIF(A:A,MID(A:A,4,2)="02",B:B)
=SUMIF(A:A,MID(A:A,4,2)="11",B:B)
Which means: If it's the second (XX.02.XXXX) month, it should sum the values from Col B based on that. If it's the 11th month (XX.11.XXXX) in Col A, it should do the same but for cells where Col A has 11.
However, it doesn't work. Apparently, one cannot do the MID function over more than one cell?

You need to use ARRAYFORMULA for that.
This one will give a column of sums for every month there is:
=ARRAYFORMULA(
SUMIF(
MID(A:A, 4, 2),
UNIQUE(MID(FILTER(A:A, A:A <> ""), 4, 2)),
B:B
)
)
And if you have those dates formatted as date, having the type date, then you can use MONTH instead of MID to get the month number:
=ARRAYFORMULA(
SUMIF(
MONTH(F:F),
UNIQUE(MONTH(FILTER(F:F, F:F <> ""))),
G:G
)
)

Related

SUMIFS With Text and Date Comparison

theoretically I want to sum the total income each employee made for all the businesses.
Like this:
Employee 1 = Biz 1 income + Biz 2 income + Biz 3 income, etc...
Employee 2 = Biz 1 income + Biz 2 income + Biz 3 income, etc...
Technically and based on the table below, I want to sum a range in column R starting from cell R14 where the text in column W starting from W14 is the same in column P starting from cell P14 AND the name of the month in column V starting from cell V14 is equal to a month in date in column N starting from cell N14.
*
(I included the date because this is part of a budget planner so I need to categorize the data based on months.)*
I used this formula:
=SUMIFS(R14:R1013, P14:P1013, U14:U1013, TEXT(N14:N1013,"MMMM"),"="&T14:T1013)
But it prompts me with the error: Array arguments to sumifs are of different size
What could be wrong here? Does someone have any idea?
Thanks for your help in advance!
Try wrapping the text formula into ARRAYFORMULA to get the full column:
=SUMIFS(R14:R1013, P14:P1013, U14:U1013, ARRAYFORMULA(TEXT(N14:N1013,"MMMM")),"="&T14:T1013)
You can get the totals for all months and all employees with query(), like this:
=arrayformula(
query(
{ text(N13:N, "yyyy-MM"), O13:R },
"select Col1, Col3, sum(Col5)
where Col3 is not not null
group by Col1, Col3",
1
)
)

Google sheets calculation for a period of time, please assist

Use sumifs to calculate "the profit" on "monday" between 0:00 and 1:00.
C:C profit, A:A date and B:B time. The function below does not return anything
=SUMIFS(C1:C1000,A1:A1000,"Monday",B1:B1000,">=00:00",B1:B1000,"<01:00")
Can someone assist me by using google sheets calculation the output being profits made between different times and for days of the week? Below is the sample data
Below is the blank sheet maker
https://docs.google.com/spreadsheets/d/1c6CcaUyry48kogVNmyogFytjGiRWwXIKO7_ikwLik4k/edit
One way to do that is to use filter(), like this:
=sum(
filter(
A2:A,
text(B2:B, "ddd") = "Mon",
value("0:00 am") <= C2:C, C2:C < value("1:00 pm")
)
)
The formula above assumes that profits are in column A2:A, dates in column B2:B and times in column C2:C as per the table shown in the question. In the event those values are in a different order in the columns suggested by the formula in the question, use this instead:
=sum(
filter(
C1:C,
text(A1:A, "ddd") = "Mon",
value("0:00 am") < B1:B, B1:B < value("1:00 pm")
)
)
You can also use named ranges, like this:
=sum(
filter(
Profit,
text(Date, "ddd") = "Mon",
value("0:00 am") <= Time, Time < value("1:00 pm")
)
)
The three named ranges must be exactly of the same height.
If the spreadsheet locale is such that the name of Monday is something else, replace Mon with something else. You should also use 24-hour time format such as 13:00 instead of 01:00 pm when the locale so requires.
The layout of data in your sample spreadsheet differs considerably from what you present in the question. Further, the values in column P are not dates but text strings that just look like dates.
With those handicaps, you can best get an hourly report pivoted by day of week using a couple of helper columns and query(), like this:
=arrayformula(
lambda(
daySerial,
if(
len(daySerial),
weekday(daySerial, 2) & text(daySerial, " dddd"),
iferror(1/0)
)
)(
iferror(value(substitute(P2:P, ".", "/")))
)
)
=arrayformula(
if(
len(Q2:Q),
value(regexextract(to_text(Q2:Q), "\d+")),
iferror(1/0)
)
)
=query(
N1:U,
"select U, sum(N)
where U is not null
group by U
pivot T",
1
)
See your sample spreadsheet.

If column A is equal to current month then do. I am needing my formula updated please

I have a formula to count number of times the word "test" is on a certain sheet
=COUNTIF(FILTER('Archived D'!E:E,ISNUMBER(MATCH('Archived D'!H:H,Match!$A$2:$A$12,0))),A2) + COUNTIF('IAD'!E:E, A:A)
I need the formula to only count total of "test" when column "A" in "IAD" is equal to the current month. I tried
+ COUNTIFS('IAD'!E:E, A:A, 'IAD'!A:A, MONTH(TODAY()))
That is giving me zero for my count and that isn't right. What am I doing wrong?
try:
=ARRAYFORMULA(IF(A2:A="",,IFNA(VLOOKUP(A2:A,
QUERY({Archive!A3:H; IAD!A:H},
"select Col3,count(Col3)
where month(Col1)+1 = "&MONTH(TODAY())&"
and Col8 matches '"&TEXTJOIN("|", 1, Names!A2:A)&"'
group by Col3"), 2, 0), 0)))

Google Sheets: Perform a running formula in the same column

I have a simple formula I want to perform in the same column.
Link to sheet
Column A: dates
Column C: multiplier
Column B: where I want to perform the formula.
B2 = B1-B1*$C$1
B3 = B2-B2*$C$1 etc
I'd like to automatically run the formula as the number of months (in Col A) changes.
​A
B
C
1/4/22
100
0.5
1/5/22
50
1/6/22
25
try:
=ARRAYFORMULA(IF(A2:A="",,B1*C1^SEQUENCE(COUNTA(A2:A))))
=arrayformula( B1 * (1 - C1) ^ sequence(count(A2:A)) )

Split 1 column into multiple columns with up to 500 cells each

In Google Sheets, I have a column that is arbitrarily long.
I want to split this column into separate columns of length 500.
How can I do this?
Some things I've been thinking may be involved in a solution:
TRANSPOSE
ARRAY_CONSTRAIN
Arrayformula, an example for number 5, change to 500.
=ArrayFormula(IFERROR(
vlookup(
(TRANSPOSE(ROW(INDIRECT("a1:a"&ROUNDUP(COUNTA(A:A)/5))))-1)*5 + ROW(INDIRECT("a1:a"&5)),
{ROW(A:A),A:A},2,)
))
ROUNDUP(COUNTA(A:A)/5 the number of columns. Up because the last column may contain less than N rows.
TRANSPOSE(...)*5 + ROW(INDIRECT("a1:a"&5)) to get matrix of numbers.
Matrix:
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
{ROW(A:A),A:A} to get the number of a row and value to return
vlookup to return a value
IFERROR to show "" if error.
Having an arbitrarily long column implies you'll need arbitrarily many columns for the split, and spreadsheet formulas cannot create new columns. So the best we can is to use all columns available.
Assuming the data column begins with cell A1, and the upper left corner of the range in which it should be split is B1, the following formula will work, if you fill the first 500 rows of the sheet with it:
=offset($A$1, row()-row($B$1) + 500*(column()-column($B$1)), 0)
Otherwise, change A1 and B1 to the top source and upper-left corner of destination.
Explanation: the offset moves from A1 down by the specified amount, which increments by 1 with every row and by 500 with every column.
You could also use this formula:
=ARRAYFORMULA(
TRIM(
SPLIT(
TRANSPOSE(
SPLIT(
QUERY(
<long_column_range> & "," & IF(
MOD(1, <columns>) = 0, "|", ""
),, 9^9
), "|"
)
), ","
)
)
)
where:
<long_column_range> is the range of the long column that you want to split (e.g. A1:A) and
<columns> is the number of columns that you want for the long column to be split into.
Taken from this article.

Resources