Combine duplicate rows, merge and sum values - google-sheets

I need to combine duplicate rows then concatenate values in column 2 and sum values in column 3, if row does not have duplicate retain values. I'm using Excel 2010.
Given;
Col1 Col2 Col3
Apple Red 2
Apple Green 5
24829 sk1 2
24829 sd2 8
123 po3 1
Bag black 7
Expected Output:
Col1 Col2 Col3
Apple Red,Green 7
24829 sk1,sd2 10
123 po3 1
Bag black 7

With Google Sheets you could try:
Col G:=unique(A2:A)
Col H:=join(",",filter(B2:B,A2:A=G2))
Col I:=sumif(A2:A,G2,C2:C)

use this one-cell solution:
=ARRAYFORMULA({UNIQUE(INDIRECT("A1:A"&COUNTA(A1:A))),
REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(QUERY(QUERY(""&A1:B,
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),
"offset 1", 0)<>"", QUERY(""&A1:B,
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0")&",", ))
,, 999^99))), ",$", ), QUERY({""&A1:A, C1:C},
"select sum(Col2) where Col1 is not null group by Col1 label sum(Col2)''", 0)})

Related

Query multiple columns of data in Google Sheets and count number occurrences

I am trying to query two columns of data in Google Sheets and count how many times the values occur.
I have made a Google Sheets formula which works but only returns data in the first column.
=QUERY(QUERY({D2:D,E2:E}, "select Col1, count(Col1) group by Col1"), "select Col1, Col2 order by Col2 desc, Col1 limit 45", 0)
How can I query and count data from both columns together?
DESIRED RESULT
2.38 / 2
5.38 / 2
...
I have made a Google Sheet showing an example. This can be copied by going to File-Make a Copy
https://docs.google.com/spreadsheets/d/1S5fE43JPVgUhZFVx-rjowkCy8N6p_ziIhIWe4MweiXQ/edit?usp=sharing
If your formula gives the correct output, you may need to change your comma with semicolon. That way all your data will be grabbed as a single column:
=QUERY(QUERY({D2:D;E2:E}, "select Col1, count(Col1) group by Col1"), "select Col1, Col2 order by Col2 desc, Col1 limit 45", 0)
Please try:
=QUERY({D2:D;E2:E},"Select Col1, COUNT(Col1) WHERE Col1 IS NOT NULL GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL COUNT(Col1)''")

Find count of String in hundred column

I have hundred data in spreadsheet. I want to know the count of that fruit name. How can i do this in Spreadsheet?
Example (expected) output:
Banana = 38
Grape = 41
Dates = 29
Orange = 32
..
etc
QUERY() would be good choice.
=QUERY(FLATTEN(B2:J),"select Col1, count(Col1) group by Col1 label Col1 'Fruits', count(Col1) 'Count'")
If you want to exclude blank cells then use
=QUERY(FLATTEN(B2:J),"select Col1, count(Col1)
where (Col1 is not null)
group by Col1
label Col1 'Fruits', count(Col1) 'Count'")

How to count values if option checked is selected in one cell

I have a spreadsheet where users fill out a form, they have multiple options they can pick by clicking the checkboxes.
The responses sheets looks like this
I want to filter the results by option, so my main goal is to get the total amount of options selected:
I've been trying with COUNTIF but it's not working because I'm not selecting the specific response
=COUNTIF('Form Responses 1'!C2:F4,"*"&$B$1&"*")
I'm assuming I need to add a VLOOKUP but I'm not sure how to match it with the option
Here's a spreadsheet to play around with it
try:
=INDEX({QUERY(TRIM(SPLIT(FLATTEN(A2:A&"×"&SPLIT(B2:B, ",")), "×")),
"select Col1,count(Col1) where Col2 is not null group by Col1 pivot Col2 label Col1 'Person'");
{"Total", TRANSPOSE(MMULT(TRANSPOSE(QUERY(QUERY(TRIM(SPLIT(FLATTEN(A2:A&"×"&SPLIT(B2:B, ",")), "×")),
"select count(Col1) where Col2 is not null group by Col1 pivot Col2"), "offset 1", )*1),
SEQUENCE(COUNTUNIQUE(TRIM(FLATTEN(SPLIT(TEXTJOIN(",", 1, B2:B), ",")))), 1, 1, )))}})
Perhaps a formula like this:
=IFNA(QUERY({$A$2:$A$6, $B$2:$B$6}, "Select 1 where Col2 contains '"&B$9&"' and Col1 = '"&$A10&"' order by Col1 label 1 ''"), 0)
This outputs a 1 if the referenced cell contains the specified text, and a 0 otherwise. See the docs for the Query Function and the Query Language for more information.

Google sheet formula to find missing number based on matching criteria

With the data in the attached google sheet, Col F (IN/OUT) will have either IN or OUT and Col J (Bag Numbers) will have numbers seperated by Comma.
Based on the sample data, for Vendor 4-Sunil, Bag numbers 2,3,4,5 where sent OUT on 8/9/21. On 17/9/21, 2,3,4,5 where received IN. So there is nothing Pending with Vendor 4-Sunil.
On the other hand with Vendor 5-Rajan, Bag numbers 13,14,15,16 where sent OUT on 14/9/21. On 25/9/21 Bag Numbers 13,15 where received IN. So the pending bags yet to be received IN from Vendor 5-Rajan is 14,16.
Is there a way to build a formula in Google sheet to indicate the number of pending Bags based on IN or OUT criteria for a given Vendor?
Thank you.
Sample Google sheet
https://docs.google.com/spreadsheets/d/10XP3k4HLteGHgOEdd0YIZR-_0p2IiHog5R7luIM5NeM/edit?usp=sharing
To display Bag numbers out, try:
=arrayformula(query({
query({A:J},"select Col5 where Col5 !='' and Col6 contains 'OUT' order by Col5",1),
regexreplace(regexreplace(regexreplace(query({A:J},"select Col10 where Col5 !='' and Col6 contains 'OUT' order by Col5",1),iferror(vlookup(query({A:J},"select Col5 where Col5 !='' and Col6 contains 'OUT' order by Col5",1),{query({A:I,iferror(regexreplace(J:J,",","|"),J:J)},"select Col5, Col10 where Col5 !='' and Col6 contains 'IN' order by Col5",1)},2,0)),""),",+",","),"^,+|,+$",)
},"where Col2 != '' label Col2 'Remaining out' ",1))
If you want a more complex solution running from a single cell that handles multiple OUT and IN for the same Vendor, then try:
=arrayformula({"Vendor","Items still out";regexreplace(query({
query(regexreplace(split(flatten(regexreplace(trim(query(transpose(query(if(E2:E<>"",substitute({E2:E&char(9998)&F2:F&char(9998),J2:J,J2:J}," ",char(9999)),),"select Col1,Max(Col2) where Col1 !='' group by Col1 pivot Col3",)),"",9^9))," ",",")),char(9998)),"^,+|,+$",),"select Col1 where Col2 contains 'OUT' order by Col1",0),
iferror(regexreplace(regexreplace(query(regexreplace(split(flatten(regexreplace(trim(query(transpose(query(if(E2:E<>"",substitute({E2:E&char(9998)&F2:F&char(9998),J2:J,J2:J}," ",char(9999)),),"select Col1,Max(Col2) where Col1 !='' group by Col1 pivot Col3",)),"",9^9))," ",",")),char(9998)),"^,+|,+$",),"select Col3 where Col2 contains 'OUT' order by Col1",0),iferror(vlookup(
query(regexreplace(split(flatten(regexreplace(trim(query(transpose(query(if(E2:E<>"",substitute({E2:E&char(9998)&F2:F&char(9998),J2:J,J2:J}," ",char(9999)),),"select Col1,Max(Col2) where Col1 !='' group by Col1 pivot Col3",)),"",9^9))," ",",")),char(9998)),"^,+|,+$",),"select Col1 where Col2 contains 'OUT' order by Col1",0),
{regexreplace(query(regexreplace(split(flatten(regexreplace(trim(query(transpose(query(if(E2:E<>"",substitute({E2:E&char(9998)&F2:F&char(9998),J2:J,J2:J}," ",char(9999)),),"select Col1,Max(Col2) where Col1 !='' group by Col1 pivot Col3",)),"",9^9))," ",",")),char(9998)),"^,+|,+$",),"where Col2 contains 'IN' order by Col1",0),",","|")}
,3,0),),),"^,+|,+$",),)
},"where Col2 !='' ",0),char(9999)," ")})

is there any functions in google sheets to resolve the below problem?

I want to filter the value in F (F>100) and group values in F according to Values in E, find the total for the group and multiply it with value in B as per the group (ie, A,B,C etc.,) and the final totals of the multiplied values for all groups
sum(A)*20+sum(B)*30+sum(C)*15 and so on
enter image description here
See if this works
=index(query({E:F, IFERROR(F:F*VLOOKUP(E:E, A:B, 2, 0))}, "Select Col1, sum(Col3) where Col2 > 100 group by Col1 label sum(Col3)''", 0))
If Col A will always have A,B,C,D,E in that order:
=arrayformula(if(A:A<>"",{A:A,QUERY({E:F},"select sum(Col2) where Col2 >100 group by Col1 label sum(Col2) '' ",0)*B:B},))
If not:
=arrayformula(if(A:A<>"",QUERY({E:F},"select sum(Col2) where Col2 >100 group by Col1 label sum(Col2) '' ",0)*query({A:B},"select Col2 where Col1 is not null order by Col1",0),))

Resources