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

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),))

Related

Most ocuring chatacter in a cell

What's the formula to find which is the most frequent character in a cell in Google Sheets?
E.G. In cell N8 it says: "What's your name?". I'd like the formula to return "a", as it is the most frequent character in N8.
you can get the total distribution like this:
=QUERY(FLATTEN(REGEXEXTRACT(A1, REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) group by Col1 order by count(Col1) desc label count(Col1)''")
notice that two empty spaces are counted as well
if you want to skip them use:
=QUERY(FLATTEN(REGEXEXTRACT(A1, REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) where Col1 <> ' ' group by Col1
order by count(Col1) desc label count(Col1)''")
also, keep in mind that this is case-sensitive:
to make it case-insensitive use:
=QUERY(FLATTEN(REGEXEXTRACT(LOWER(A1), REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) where Col1 <> ' ' group by Col1
order by count(Col1) desc label count(Col1)''")
so to get the top value only use:
=INDEX(QUERY(FLATTEN(REGEXEXTRACT(LOWER(A1), REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) where Col1 <> ' ' group by Col1
order by count(Col1) desc label count(Col1)''"), 1, 1)
This should work:
=index(Sort(filter({LEN(substitute($A$1,mid($A$1,ROw(A:A),1),"")),mid($A$1,ROw(A:A),1)},Row(A:A)<= LEN(A1)),1,true),1,2)
I'm not sure what you'd expect for when there's a tie, but it would consistently return the character most used. If you wanted to skip spaces, you could do this...
=index(Sort(filter({LEN(substitute($A$1,mid(substitute($A$1,"
",""),ROw(A:A),1),"")),mid(substitute($A$1," ",""),ROw(A:A),1)},Row(A:A)
<= LEN(substitute(A1," ",""))),1,true),1,2)

Google sheet, select columns within a named range

I'm trying to select a range of data within a named range on a google sheet but after searching I still can't figure it out how to do it.
In this case, I would like to count the amount of time a club appeared within a gameweek.
Here I can do it for all the gameweek tables I have, there is no problem.
Total
=QUERY({B:C;D:E;F:G;H:I;J:K}; "SELECT Col1, SUM(Col2) WHERE Col1 <> '' AND Col1 <> 'GK' AND Col1 <> 'DEF' AND Col1 <> 'MID' AND Col1 <> 'FW' AND Col1 <> 'EXTRA' AND Col1 <> 'Club' AND Col1 <> 'count' AND Col1 MATCHES '^.{0,5}$' GROUP BY Col1 ORDER BY SUM(Col2) DESC LABEL Col1 'Club', SUM(Col2) 'count'")
But I'd like to do the same for each of the gameweek table. So far I have this
Gameweek 1
=QUERY({(B6:B15):(C6:C15);(D6:D15):(E6:E15);(F6:F15):(G6:G15);(H6:H15):(I6:I15);(J6:J15):(K6:K15)}; "SELECT Col1, SUM(Col2) WHERE Col1 <> '' GROUP BY Col1 ORDER BY SUM(Col2) DESC LABEL Col1 'Club', SUM(Col2) 'count'")
but it is not very usable as I'd have to change each range for every next table.
So I tried to make the "Gameweek 1" table as a named range gw1_clubcount and only select its adequate columns similarly as the total so that I would just have to change that for each gameweek but obviously it is not working but that's what I would like to reach.
Gameweek 1 with named range
=QUERY(gw1_clubcount {B:C;D:E;F:G;H:I;J:K}; "SELECT Col1, SUM(Col2) WHERE Col1 <> '' GROUP BY Col1 ORDER BY SUM(Col2) DESC LABEL Col1 'Club', SUM(Col2) 'count'")
I've found the INDEX function where you can select the desired row and column of the named range.That would give something like this below but that's not how you use it.
=QUERY({INDEX(gw1_clubcount,,1):INDEX(gw1_clubcount,,2);INDEX(gw1_clubcount,,3):INDEX(gw1_clubcount,,4);INDEX(gw1_clubcount,,5):INDEX(gw1_clubcount,,6);INDEX(gw1_clubcount,,7):INDEX(gw1_clubcount,,8);INDEX(gw1_clubcount,,9):INDEX(gw1_clubcount,,10)} ; "SELECT Col1, SUM(Col2) WHERE Col1 <> '' GROUP BY Col1 ORDER BY SUM(Col2) DESC LABEL Col1 'Club', SUM(Col2) 'count'")
I'm not very experienced with sheets and a little help would be very appreciated !
Here I created a solution that requires custom function:
To write a custom function:
Create or open a spreadsheet in Google Sheets.
Select the menu item Tools > Script editor.
Delete any code in the script editor.
For this problem, simply copy and paste the code below (stack function) into your script editor.
At the top, click Save save.
To use custom function:
Click the cell where you want to use the function.
Type an equals sign (=) followed by the function name and any input value — for example, =DOUBLE(A1) — and press Enter.
The cell will momentarily display Loading..., then return the result.
Code:
function stack(arr) {
var flatArr = arr.flat();
var filtered = flatArr.filter(function (el) {return el != "";});
const newArr = [];
while(filtered.length) newArr.push(filtered.splice(0,2));
return(newArr);
}
Named Ranges:
Example usage:
GAMEWEEK1:
=QUERY(stack(FLATTEN(gw1_clubcount)), "SELECT Col1, SUM(Col2) WHERE Col1 <> '' GROUP BY Col1 ORDER BY SUM(Col2) DESC LABEL Col1 'Club', SUM(Col2) 'count'")
GAMEWEEK2:
=QUERY(stack(FLATTEN(gw2_clubcount)), "SELECT Col1, SUM(Col2) WHERE Col1 <> '' GROUP BY Col1 ORDER BY SUM(Col2) DESC LABEL Col1 'Club', SUM(Col2) 'count'")
References:
Custom Function
FLATTEN

add order by to query formula that gets unique list and count from delimited strings in a column Google sheets

I have a formula that gets a unique list of titles from pipe-delimited string in a column and there counts
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN("|",Elements!$H2:$H),"|")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))
I need to sort the counts in a descending manor, I have tried adding order by Col2 Desc
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN("|",Elements!$H2:$H),"|")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) order by Col2 Desc''",0))
But I get unable to parse ...
Thank you
use:
=INDEX(QUERY(TRANSPOSE(SPLIT(JOIN("|", Elements!H2:H), "|")&{"";""}),
"select Col1,count(Col2)
group by Col1
order by count(Col2) desc
label count(Col2)''", 0))

Combine duplicate rows, merge and sum values

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)})

Google Sheets Query Language, return 0

I've been having troubling getting the query function to return 0 when the queried data isn't found.
Given the following data...
With each sheet being a different player, I need to count the number of games each played and the outcome of those games.
Some players may be in the same game as each other so the gameIDs are given as a unique identifier so those games are only counted once, that part I have working.
What I'm trying to do now is record the number of wins team A has in each room.
You can see my problem in the above screenshot.
Here is the sample sheet that has the above data.
This is the formula used for the right most example
=QUERY({QUERY(UNIQUE(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 <> '' and Col3 contains 'A'")),"select Col1, 1");QUERY(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 = '' and Col1 <> '' and Col3 contains 'A'"),"select Col1, 1")},"select Col1, sum(Col2) where Col1 <> '' group by Col1 label sum(Col2) 'TeamA Wins', Col1 'Room'")
Anyone able to help?
You may add dummy data into the formula:
=QUERY(data;{QUERY(UNIQUE(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 <> '' and Col3 contains 'A'")),"select Col1, 1");QUERY(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 = '' and Col1 <> '' and Col3 contains 'A'"),"select Col1, 1")},"select Col1, sum(Col2) where Col1 <> '' group by Col1 label sum(Col2) 'TeamA Wins', Col1 'Room'")
^^^^
data is a named range, it looks like this:
To make it:
paste the data to separate sheet, as shown in picture above.
select range A1:B6
go to Data → Named range → call it "data"
enter the formula and it should work fine now.
Sample file with working formula

Resources