I have two columns:
Col A Col B
01.02.2020 17
03.11.2020 24
03.11.2020 12
As I stated in another question, I tried to sum Col B, based on the month in Col A. The solution was the following formula (without the sort):
=ARRAYFORMULA(
SUMIF(
MID(A:A, 4, 2),
SORT(UNIQUE(MID(FILTER(A3:A, A3:A <> ""), 4, 2))),
B:B
)
)
Something I missed was the population of missing months. Therefore my question is: How can I populate the result table with the missing months and zeroes until values are entered? The desired output for the table above would be:e
Col A Col B Col C
01.02.2020 17 0
03.11.2020 24 17
14.12.2020 100 0
03.11.2020 12 0
0
0
0
0
0
0
36
100
If just doing it for the current year, this should be enough
=ArrayFormula(sumif(mid(A2:A,4,2),sequence(12),B2:B))
alternative:
=ARRAYFORMULA(IFNA(VLOOKUP(ROW(A1:A12), QUERY(A:B,
"select month(A),sum(B) group by month(A)"), 2, 0), 0))
Related
For example, I would like the formula to lookup the UID 4119.502914 and count the number of non-blank cells in the range C2:G2. The result would be 0 in this case.
Here is the data table:
UID
Active since
Level A1 result
Level A2 result
Level B1 result
Level B2 result
Level C1 result
4119.502914
16/03/2022
32502.84434
16/03/2022
3439.094252
21/03/2022
B
78344.29029
05/08/2022
82511.53052
24/05/2022
40939.00908
16/03/2022
A
A+
A
A+
19481.28071
30/03/2022
6259.532774
04/08/2022
13352.59697
04/08/2022
A+
C
54786.31186
18/03/2022
82548.2726
16/03/2022
B+
B+
50125.47835
04/08/2022
27984.35676
04/08/2022
A
Here is the expected result:
UID
Count
4119.502914
0
32502.84434
0
3439.094252
1
78344.29029
0
82511.53052
0
40939.00908
4
19481.28071
0
6259.532774
0
13352.59697
2
54786.31186
0
82548.2726
2
50125.47835
0
27984.35676
1
Could try the following formula-
=COUNTIFS(INDEX($C$3:$G$15,XMATCH(H3,$A$3:$A$15)),"<>")
Given I have the following sheet data
What I'm trying to do is count the amount of times Yes appears in each column.
So, I'm looking for something like
Header 1:
B: 1
C: 1
D: 0
Header 2:
B: 1
C: 4
D: 1
Header 3:
B: 2
C: 1
D: 0
I've tried looking at using MOD and with the formula
=ARRAYFORMULA(MOD((ROW(B1:B14)), 5))
I can get the index, then maybe do some offset? The above formula prints
1
2
3
4
0
1
2
3
4
0
1
2
3
4
I'm not too sure where to go from here though.
Desired output
EDIT
Based on the accepted answer, I amended the formula slightly. This was because the cell in A wasn't guaranteed to be empty if it wasn't a header, so I used a REGEXMATCH
=
ArrayFormula(
query(
{
if(mod(row('Runs 93 - 300'!H:H), 14) = 0,
"",
vlookup(row('Runs 93 - 300'!H:H), {
if(regexmatch('Runs 93 - 300'!H:H, "RUN #\d+"), row('Runs 93 - 300'!H:H)),
'Runs 93 - 300'!H:H
}, 2)
),
if('Runs 93 - 300'!M:Q="Yes",1,)
},
"select Col1,count(Col2),count(Col3),count(Col4),count(Col5), count(Col6) where Col1 is not null group by Col1 label count(Col2) '',count(Col3) '',count(Col4) '', count(Col5) '', count(Col6) ''"
)
)
This does make the first cell in the formula output #RUN 300 #RUN 300 but I can accept that.
You can use Vlookup to copy the header down through the rows that are blank in column 1, then use a Group By query to do the counts:
=ArrayFormula(query({if(mod(row(A:A),5)=0,"",vlookup(row(A:A),{if(A:A<>"",row(A:A)),A:A},2)),if(B:D="Yes",1,)},"select Col1,count(Col2),count(Col3),count(Col4) where Col1 is not null group by Col1 label count(Col2) '',count(Col3) '',count(Col4) ''"))
You could avoid doing a Vlookup on every row (or rather four out of five rows) by limiting it to the rows where the data is:
=ArrayFormula(query({if(row(A:A)>counta(A:A)*5,"",vlookup(row(A:A),{if(A:A<>"",row(A:A)),A:A},2)),if(B:D="Yes",1,)},"select Col1,count(Col2),count(Col3),count(Col4) where Col1 is not null group by Col1 label count(Col2) '',count(Col3) '',count(Col4) ''"))
You can try this too:
={filter(A:A,A:A<>""),index(transpose(len(array_constrain(trim(RegexReplace(split(transpose(query(B:D,,9^9))," ",0),"No|\s",)),9^9,3))/3))}
A B C
Val 1 2
Val 2 1
Val 3 1
Item 1 Val 1 1
Item 2 Val 2 1
Item 3 Val 3 0
Item 4 Val 1 0
Consider the above sheet. In the first 3 rows I am counting how many times corresponding val# shows up in the sheet. I have done that with: =COUNTIF($B$5:$B, A1) However, I can't figure out how to make it count only if the value matches and column C doesn't have a 1 next to it on same row. Is this possible?
try COUNTIFS:
=COUNTIFS(B$5:B, A1, C$5:C, "<>"&1)
make sure C column is formatted as Number
I have the following sheet.
H I J K ... BD
2,3 4 2,4,7 ... 1
3,7 10 ... 8,13
The cell ‘H’ has 2,3 as text but cell ’I’ has the number 4, cell ‘J’ has the 2,4,7 as text and cell ‘BD’ has 1 as a number. All the cells that have 2 or more numbers as text are separated by commas
I want to sum all numbers and non-numbers to one single row using array-formula.
The result must be
BE
16
41
The range is between H2:BD with H1:BD1 for the headers
I have used this code:
=arrayformula(if(row(A1:A)=1;"BottleQty";if(len(A1:A)>0;
SUBSTITUTE(transpose(query(transpose(H1:BD);;COLUMNS(H2:BD)));",";"");iferror(1/0))))
but the result is
BE
2 3 4 2 4 7 1
3 7 10 8 13
Any help ??
Thanks in advance
=ARRAYFORMULA(IF(LEN(TRIM(TRANSPOSE(QUERY(TRANSPOSE(A2:D),,99^99)))),
MMULT(IFERROR(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(A2:D),,99^99)), ", ")*1, 0), ROW(INDIRECT("A1:A"&
COLUMNS(IFERROR(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(A2:D),,99^99)), ", ")*1, 0))))^0), ))
I have arrayformula in the first row of a column so my values and calculations can start in Row 2 and for all the column length.
I have this situation:
https://docs.google.com/spreadsheets/d/11oDra7Vja4-5C0Uix7JTgLLSMG3gPj-6fkajXlWqqQk/edit?usp=sharing
I need a simply arithmetic operation:
Subtract above value of the same column for every row.
I'm using:
=arrayformula(IF(row(A:A)=1; "What I have now"; IF(ISBLANK(A:A); ""; A1:A-A2:A)))
but as you see is wrong.
How to do that?
UPDATED QUESTION:
And then in the second sheet I need a SUM operation with some blank cells in column:
How to do that?
https://docs.google.com/spreadsheets/d/11oDra7Vja4-5C0Uix7JTgLLSMG3gPj-6fkajXlWqqQk/edit#gid=931743679
If you want to have the array formula ion the header this is a bit weird as you need to allow the formula to technically access row 0, we can do this by constructing ranges.
=ArrayFormula(IF(
--(ROW(A1:A) > 2) + -ISBLANK(A1:A) = 1;
{0; A1:A} - {0; A2:A; 0};
""))
--(ROW(A1:A) > 2) + -ISBLANK(A1:A) = 1 Checks if the row is populated and not one of the first two rows in a way that works nicely with array formulas
{0; A1:A} - {0; A2:A; 0} does the following:
0 Data 156 123 110 95 42
- - - - - - -
0 156 123 110 95 42 0
= = = = = = =
0 33 13 15 53 42 42
N N Y Y Y Y N <- Is shown
^ ^ ^
| | Because Row is blank
| |
Because row not > 2, thus it is never evalauated even though the second would cause an error
I think this is quite tricky. The problem is that in an array formula the number of cells in each array must match - you can't mix an array starting in row 1 with an array starting in row 2 if they go all the way to the bottom of the spreadsheet.
Here is one way of getting the result you want
=arrayformula({"What I need";"";offset($A$1,1,0,count(A:A)-1)-offset($A$1,2,0,count(A:A)-1)})
You will need to change the ; and , for your locale.
I have built up an array using the {} notation to define the elements. In my locale a ; means go to the next row, so I have defined the first two cells directly as strings. After that I've chosen to use Offset to get the range A2:A5 (1 row down from A1, 0 rows across and 4 cells high) and subtract the range A3:A6 (2 rows down from A1, 0 rows across and 4 cells high) it so that gives me the other 4 cells.
B1 "What I need"
B2 ""
B3 A3-A2=33
B4 A4-A3=13
B5 A5-A4=15
B6 A6-A5=53
but will need an IF statement adding if there are any blank cells between the numbers.
In the particular case of your updated question where there are fewer numbers in column D than column C, the formula would be
=arrayformula({"Special Case";"";offset($D$1,1,0,count(D:D))+offset($C$1,2,0,count(D:D))})
But in the general case of there being blank cells anywhere, you would have to test everything
=arrayformula({"General Case";"";if(offset($D$1,1,0,rows(C:C)-2)="","",if(offset($C$1,2,0,Rows(C:C)-2)="","",offset($D$1,1,0,rows(C:C)-2)+offset($C$1,2,0,Rows(C:C)-2)))})