Sum same values in different columns (Google Spreadsheet) - google-sheets

I've got two columns, A with the date and B with the revenue. Some dates are duplicated and I'd like to omit the duplicate dates and to sum the revenue values from the same date.
It would be something like bringing this:
12/04/2014 5$
12/04/2014 5$
13/04/2014 6$
13/04/2014 6$
to this:
12/04/2014 10$
13/04/2014 12$

You could use query to achieve this. If your data is in columns A & B with headers, you could use:
=Query($A$1:$B$5,"select A,sum(B) group by A", 1)
Here is a sample sheet.

You also can use:
=unique(A), this will return each date
=sum(filter(B:B,A=date_row), sum each time that date appears
I hope it works for you!
Regards

Related

How to sum values in a column based on day of the week in Google sheets

I have a Spreadsheet with duration values in one column, and date values in another.
I want to sum duration values based on a particular day of the week... eg, in the example screenshot, the first and last dates are Friday. So I want a formula that would add the duration values from the corresponding cells... a total of 17:00
I've tried a formula like this. But this doesn't work.
=SUMIF(D:D, CHOOSE(WEEKDAY(DATE(),2), "Fri") , A:A)
You could try:
=sumproduct(weekday(A:A)=6,D:D)
try:
=TEXT(ARRAYFORMULA(SUMIF(WEEKDAY(A:A, 11), 5, D:D)), "[h]:mm")
Not sure if there is an easy way because I'm noob at Google Sheets, but try with array formula:
=ArrayFormula(SUMIF(D1:D3;WEEKDAY(A1:A3;2);5))
Using it as array formula, I got this:
Hope this helps
One approach to do this is the following:
In column E put the weekday values. Use WEEKDAY() function which depending on your setting will make Friday any integer between 1-7. If using default Friday will be "6".
Use the SUMIF() function. Eg.=sumif(E:E,"=6",D:D)
Make sure the cell where your SUMIF() formula resides, also has a duration number format.

Google Sheets sum rows with the same first cell value grouped by first row value

I have dynamic data for an online shop with sales by product, by week split into columns:
I want to create a header row of the unique weeks and summarise the total sales by product by week in a dynamic table using query and or array formula if possible. However, Arrays and Queries seem to be designed for data exclusively in columns so maybe I need to transpose it in some way? Any ideas?
you can do:
=QUERY(B2:E, "select B,C+D,E label C+D''", 0)
or:
=ARRAYFORMULA({IF(B99=C99, B100:B+C100:C, B100:B),
IF(C99=D99, C100:C+D100:D, C100:C),
IF(D99=E99, D100:D+E100:E, D100:D),
IF(E99=F99, E100:E+F100:F, E100:E)})
Okay, so I took my own advice and did a transpose to get the data into a state that Query can work with and then re-transposed it back to get the format I wanted. However, it's not exactly dynamic as I'd have to edit the formula if we added or took away any products.
=Transpose(query(transpose(A2:E13),"Select Col1, Sum(Col2), Sum (Col3), Sum(Col4), Sum(Col5), Sum(Col6) ,Sum(Col7), Sum(Col8), Sum(Col9), Sum(Col10), Sum(Col11), Sum(Col12) group by Col1",1))
Which produces a nice tabular result:
Any ideas how to make the formula more dynamic?

Google Spreadsheet SUMIF with criterion containing wildcards

Please see the data example in the image below...
I would like to sum the amounts separately by months and years.
How can I do this using SUMIF ?
My idea was very simple - to have formula for each month and for each year, like this:
=SUMIF(A1:A100,"2018-01-*",B1:B100)
=SUMIF(A1:A100,"2018-02-*",B1:B100)
=SUMIF(A1:A100,"2018-03-*",B1:B100)
..etc
=SUMIF(A1:A100,"2018-*",B1:B100)
=SUMIF(A1:A100,"2019-*",B1:B100)
..etc
But this formulas don't work. Something is wrong with the criterion.
So what am I doing wrong ? Am I using wildcards incorrectly ?
Example of data that I have
The problem here is that cells containing dates are special and cannot be compared to criterion like 2018-08-*.
The workaround is to use SUMIFS and then set each criterion with the DATE() function. Here is example for 2018-07:
=SUMIFS(B2:B100,A2:A100,">="&DATE(2018,7,1),A2:A100,"<"&DATE(2018,8,1))
You could use Query as in the image below (showing sum for 8th month - August):
By changing month(A)+1=8 you will have different months.
Code:
=QUERY(A1:B5;"select sum(B) where month(A)+1=8 label sum(B) ''";0)
Is that OK for you?

Google Sheets - comparing dates and returning the latest row with requirements

I have a sheet that uses a query to pull data from another sheet. This data, looks a bit like this.
DATE STOREID OTHERDATA
02/11/2017 Store 1 Other data 1
01/11/2017 Store 1 Other data 2
09/10/2017 Store 2 Other data 3
05/10/2017 Store 2 Other data 4
I'm looking for a way for it to return only the latest date row per store, as seen below.
DATE STOREID OTHERDATA
02/11/2017 Store 1 Other data 1
09/10/2017 Store 2 Other data 3
The query I'm currently using looks something like this:
=query(DATASHEET!A2:CF11, "select C, CC, L,CD, E, BZ, CA, CB where (BF='CUSTOMERNAME1') order by C desc, CC, L, BZ desc",0)
Is this possible to make the query look at all dates and storeIDs and only return the highest date per storeID? I can imagine doing this in another language with a loop/for, but my Google results tell me it's not possible with query.
If that is the case, how would you recommend I do this in the data sheet so I could have a column say either LATEST / NOT LATEST for each row and then use query with a WHERE statement?
Here's an example sheet I tried setting up in case it helps explain what I'm trying to do.
https://docs.google.com/spreadsheets/removed
Any help is appreciated as I've spent all day trying to figure it out. Let me know if anything is unclear.
Thanks!!
Try this one:
=ARRAYFORMULA(VLOOKUP(QUERY({ROW(A2:A),SORT(A2:C)}, "SELECT MAX(Col1) WHERE Col3 IS NOT NULL GROUP BY Col3 LABEL MAX(Col1)''",0),{ROW(A2:A), SORT(A2:C)},{2,3,4},0))
Try this:
=ARRAYFORMULA(VLOOKUP(UNIQUE(B1:B11),SORT({B1:C11,A1:A11},3,0),{3,1,2},0))
By Reverse SORTing by Column A, and VLOOKUPing UNIQUE values, We have the latest row.

Address lookup after filter

I have a Google form and a spreadsheet that is supposed to process it. The spreadsheet needs to filter the responses by date and get their respective data after that.
E.g. Consider:
With the columns being A and B and the rows being 1-4.
How do I filter it by month in ascending order followed by adding the amount next to it?
So it would look something like:
I understand how to filter by month in ascending order. It is done using =SORT(FILTER(A:A, MONTH(A:A)=1)) (for Jan). But how do you get the data next to it? I have tried =INDIRECT(ADDRESS(SORT(FILTER(A:A, MONTH(A:A)=1)), 2)) but there is no error and it is blank.
You can do SORT for whole A:B instead of doing only for A:A.
Eg:
SORT(FILTER(A:B, MONTH(A:A)=1),1,TRUE) for Jan
SORT(FILTER(A:B, MONTH(A:A)=2),1,TRUE) for Feb
Please refer link here and see whether this is what you expect.
try this:
=QUERY(A:B,"select month(A), A, sum(B) where not A is null group by month(A), A")
or this:
=QUERY(A:B,"select day(A), sum(B) where not A is null group by day(A) pivot month(A)")
or you could use your formula =SORT(FILTER(A:A, MONTH(A:A)=1)) twice and use custom date format for first column to label it as JAN, FEB...

Resources