Excel Formula for counting words with same starting letters - google-sheets

Suppose I have a column of words, in some cases more than 1 word in each cell, separated by a comma or space. I want to calculate the number of words starting with A, B, C...,Z separately.

try:
=ARRAYFORMULA(QUERY(IFERROR(FLATTEN(REGEXEXTRACT(SPLIT(A1:A10; ", "); "^.")));
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''"))
or:
=ARRAYFORMULA(QUERY(IFERROR(UPPER(FLATTEN(REGEXEXTRACT(SPLIT(A1:A10, ", "), "^.")))),
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''"))

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 Sheets multiply values in cell by both integer in same cell and number of TRUE in same row

I have the following formula:
=ARRAYFORMULA(QUERY(IFERROR(FLATTEN(SPLIT(FLATTEN(REPT(REGEXEXTRACT(SPLIT(A1:A4, " "),
"(?:\d+x)?(.+)")&"×", IFERROR(REGEXEXTRACT(SPLIT(A1:A4, " "), "(\d+)x"), 1)*1)), "×"))),
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''"))
This counts the number of entries in column A, extracting the variable text like 2x and 1x, then lists them as unique cells accompanied by a count of each (while ignoring empty cells).
Now, I'd like to modify this to count associated checkboxes in 3 previous columns, comparing with the unique entries of the original column, as well as comparing the variable number of 2x and 1x so that it appropriately assigns the values.
In other words, I want it to turn out like so:
I've tried to modify the previous formula by adding (what I thought was) an additional range to the second FLATTEN.
=ARRAYFORMULA(QUERY(IFERROR(FLATTEN(SPLIT(FLATTEN(REPT(REGEXEXTRACT(SPLIT(D1:D14, " "),
"(?:\d+x)?(.+)")&"×", IFERROR(REGEXEXTRACT(SPLIT(D1:D14, " "), "(\d+)x"), 1)*1)), "×"),
SPLIT(REPT(COUNTIF(A1:A=true,D4:D<>"")*1), "×"))),
"select Col1,count(Col1) where Col1 is not null group by Col1 order by count(Col1) DESC label count(Col1)''"))
Among many others as I've begun to understand the formula given, I also tried a very roundabout way, first removing the QUERY part of the above to separate the Unique Strings into one column, and count into the other:
=FLATTEN(REPT(COUNTIF(B1:C=true,D1:D=F1),IFERROR(REGEXEXTRACT(SPLIT(N4:N56, " "), "(\d+)x"), 1)*1))
None of those worked.
So again, how would I get the following results?
try:
=ARRAYFORMULA(QUERY(""&IFERROR(FLATTEN(SPLIT(FLATTEN(
IF((A1:C15=TRUE)*NOT(REGEXMATCH(D1:D15, "\d+x")), D1:D15,
IF(REGEXMATCH(D1:D15, "\d+x"), REPT(REGEXEXTRACT(SPLIT(D1:D15, " "), "\d+x(.*)")&"×",
REGEXEXTRACT(SPLIT(D1:D15, " "), "(\d+)x")*1), ))), "×"))),
"select Col1,count(Col1) where Col1 is not null group by Col1
order by count(Col1) DESC label count(Col1)''"))

Max Sum of row within date range - Google Sheets

I am using Google Sheets.
I have names in first column, dates in first row, and numbers for each name/date.
I want to return the name and sum of numbers for the person who's sum of numbers is the largest (within date range.)
A cell formula for this would be better than a script.
It sounds straight forward but am going in circles and would appreciate help. Thanks Newman
Thank you.
try:
=INDEX(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"))
and for just 1 record:
=INDEX(QUERY(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"), "limit 1", 0)

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

Count how many times certain text combinations occurs in certain columns

I have a data set with multiple columns and roughly 1000 rows. I need to find out how many times certain combinations of columns can be found within the data set.
In my example below, columns A:B represents the raw data set. In C2 I have a formula that finds all non-unique combinations from columns A:B. What I need is a formula that counts how many times combinations in columns C:D are found within columns A:B. The desired output should be in ColE.
you can do it all in one go... delete columns C, D, E and use this formula:
=ARRAYFORMULA(QUERY({A2:B, A2:A&B2:B},
"select Col1,Col2,count(Col3)
where Col1 is not null
group by Col1,Col2
order by count(Col3) desc
label count(Col3)''"))
for a selected combination only use this formula in E2 cell:
=ARRAYFORMULA(IFERROR(VLOOKUP(C2:C&D2:D, QUERY({A2:A&B2:B},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''"), 2, 0)))
It's always better to share a copy of your spreadsheet, but try entering in E1
={"Count"; ArrayFormula(IF(LEN(C2:C), VLOOKUP(C2:C&D2:D, query({A2:A&B2:B, A2:B}, "Select Col1, count(Col3) where Col1 <>'' group by Col1"), 2, 0),))}
and see if that works?
Note that you can create the same output (columns C, D and E) with a single formula
=query(ArrayFormula(query({A2:B, A2:A&B2:B}, "Select Col1, Col2, count(Col3) where Col1 <>'' group by Col1, Col2")), "where Col3 >1 label Col1 'Value 1', Col2 'Value 2'")

Resources