I need to count items per person per date in google sheets. What formula do you recommend for?
I write this but it does not work:
=countifs(A2:A11, "3/14/2020", B2:B11, "person1", D2:H11, "*")
View image:
You could use a Pivot table
Have a look at the attached spreadsheet
https://docs.google.com/spreadsheets/d/....
Please read more about how to create and use Pivot Tables
Another way is to use the mmult method to get the row totals, then follow it with a grouping or pivot query:
=ArrayFormula(query({A2:B11,mmult(n(D2:H11="*"),transpose(column(D2:H11)^0))},"select Col2,Col1,sum(Col3) group by Col2,Col1"))
or
=ArrayFormula(query({A2:B11,mmult(n(D2:H11="*"),transpose(column(D2:H11)^0))},"select Col2,sum(Col3) group by Col2 pivot Col1"))
Since the range of first criteria is only one column, succeeding criteria should also use the same range, one column.
B2:B11, "person1", D2:D11, "*", E2:E11, "*" ...
reference: Each additional range must have the same number of rows and columns as the first range (criteria_range1 argument).
Related
I have a google sheet, wherein the first two columns are filled using "Arrayformula" from a pivot table. Is it possible to merge some of the cells in first column while using Arrayformula.
Below is an image of sample data which I am obtaining from the pivot. I would like to have "Porsche" from 1st column to be text wrapped for all its corresponding customer IDs.
https://i.stack.imgur.com/Pdt4I.png
Thank you
You can try using query to filter out rows where there are no Customer IDs.
Formula:
=arrayformula(query({A1:B}, "where Col2 is not null"))
Output:
If this isn't the one you want, kindly provide your expected result as I'm unsure with how you used the term "text wrapped"
I have searched on a lot of pages but I cannot find a solution to my problem except in reverse order. I have simplified what I do, but I have a query that comes looking for information in my data sheet. Here there are 3 columns, the date, the amount and the source.
I would like, with a query function, to be able to make different columns which counts the information of column C based on the values of its cells per month, like this
I'm okay with the start of the formula
=QUERY(A2:C,"select month(A)+1, sum(B), count(C) where A is not null group by month(A)+1")
But as soon as I try a little different things by putting 2 query together in an arrayformula, obviously the row count doesn't match as some minus are 0 for some sources.
Do you have a solution for what I'm trying to do? Thank you in advance :)
Solution:
It's not possible in Google Query Language to have a single query statement that has one result grouped by one column and another result grouped by another.
The first two columns can be like this:
=QUERY(A2:C,"select month(A)+1, sum(B) where A is not null group by month(A)+1 label month(A)+1 'Month', sum(B) 'Amount'")
To create the column labels for the succeeding columns, use in the first row, in my example, I1:
=TRANSPOSE(UNIQUE(C2:C))
Then from cell I2, enter this:
=COUNTIFS(arrayformula(month($A$2:$A)),$G2,$C$2:$C,I$1)
Then drag horizontally and vertically to apply to the entire table.
Results:
try:
=INDEX({
QUERY({MONTH(A2:A), B2:C},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label Col1'month',sum(Col2)'amount'"),
QUERY({MONTH(A2:A), B2:C, C2:C},
"select count(Col3) where Col2 is not null group by Col1 pivot Col4")})
I have a Google Sheet (Test Sheet 2) with two sheets in it, Sheet 1 and Sheet 2. Sheet 2 is where all of the data is and I need to get the sums of the counts of that column based on three criteria into sheet 1 column C. The name, week, year and count need to match up. I used the formula
=arrayformula(iferror(vlookup(A2:A&2020&B2:B, {Sheet2!A2:A&Sheet2!B2:B&Sheet2!C2:C, Sheet2!D2:D}, 2, FALSE)))
but that only works for unique rows. In the example sheet I am providing, the formula works well for Bill, Lisa, Katie and Jon because they all have one value for 'count' from Sheet2 when the parameters of name, week and year match up. But Mike has two rows matching the criteria. This formula returns the first match which is 3. The other value is 4 so I would like the count in Sheet1 to show 7 instead of 3. I need it to add them up.
I also tried to use sumifs but the columns are two different sizes so that didn't work.
Any idea? I did try to combine sumif with the above formula but that did not work either.
Link to Test Sheet
Solution with ARRAYFORMULA and SUMIF
If you need to use ARRAYFORMULA to improve the performances you can use this tweak of the SUMIF statement: basically you can concatenate the conditions to make them create a single AND condition.
This would be a possible solution for the formula in your comment:
=ARRAYFORMULA(SUMIF(Sheet2!A2:A&Sheet2!B2:B,A2:A&2020,Sheet2!D2:D))
Solution with SUMIFS
If you are looking for a solution with the SUMIFS formula you can use this:
SUMIFS('sum_range', 'criteria_range', condition, ['criteria_range_2', condition_2])
In your case this will translate to:
=SUMIFS(Sheet2!D2:D, Sheet2!A2:A, A2, Sheet2!B2:B, 2020)
In this case the ranges dimensions won't affect the formula execution.
Just drag this formula for the Sheet1 table column and you will get the results. The drawback is that you cannot use ARRAYFORMULA with SUMIFS. Performance wise, if you have a lot of rows in the Sheet1 I suggest using the ARRAYFORMULA solution, since this will trigger a lot of formula calls instead of just one.
Try this query()
=query(Sheet2!A:D, "Select A, C, sum(D) where B = 2020 group by A, C label C 'Week', sum(D) 'Count'", 1)
UPDATED:
If you really need to use vlookup in arrayformula() you can always ise the query (that deals with the summing) as the lookup range. In the spreadsheet I used
=ArrayFormula(if(len(A2:A), iferror(vlookup(A2:A&year(D2:D)&E2:E, query({Sheet2!A:A&Sheet2!B:B&Sheet2!C:C, Sheet2!D:D}, "Select Col1, sum(Col2) where Col1 <>'' group by Col1", 1), 2, 0)),) )
and see if that helps?
I am using a query formula to import data from a different sheet.
However after querying the data, I got the same code which I need to sum the episode and the value with unique formula therefore after querying only show unique code. I'm not sure how to mix the formula.
My query formula is the following:
=QUERY(Paste!A:M,"SELECT A,B,C ORDER BY C DESC LIMIT 15")
My spreadsheet link is the following:
https://docs.google.com/spreadsheets/d/1A6lGIlU147Y_0WFD7Btkq4IMuY-Z3D1HsNiTgjLjm0o/edit?usp=sharing
As above image. Under column A I have same code for FMEM1 due to my raw data separate it for some reason. I don't want the same code separated. I want unique code not separated and sum the episode and sum the value
try
=query({A3:A17,B3:B17,C3:C17},"select Col1, Sum(Col2),Sum(Col3) group by Col1 label Col1 'Code',Sum(Col2) 'Total Episode',Sum(Col3) 'Total Value'")
Screenshot
How can I go from wide to long in Google Sheets based on two different columns or create a pivot table where I specify two different columns from the original matrix as rows?
Please see example for intended effect:
you can do it like this all in one go:
=ARRAYFORMULA(QUERY({
A1:B, TEXT(C1:C, "hh:mm");
A2:A, D2:D, TEXT(C2:C, "hh:mm")},
"select Col2,max(Col1)
where Col2 is not null
group by Col2
pivot Col3", 1))
Here's a fairly simple approach. I don't think you can use a pivot table because the values have to be summaries of a numeric value, or at least counts, not a string value.
To get the times:
=transpose(C2:C)
To get the lecturers (fairly big assumption that there are no lecturers that work only as assistants but this can be changed later):
=unique(B:B)
If there are additional lecturers working only as assistants:
=unique({B:B;D2:D})
Then to get the topic corresponding to a particular lecturer or assistant:
=ArrayFormula(IFERROR(vlookup(filter(F2:F,F2:F<>"")&filter(G1:1,G1:1<>""),{B2:B&C2:C,A2:A},2,false))&
IFERROR(vlookup(filter(F2:F,F2:F<>"")&filter(G1:1,G1:1<>""),{D2:D&C2:C,A2:A},2,false)))