I have a Google Sheets cell containing a list of people attending an event. Some of the guests will bring friends. So the cell (A1) can look like this:
Ben, Sarah + 2, James , Mary + 5
I need to count the total number of people attending, which in this case is 11. And so I was thinking of using a formula along these lines:
=count(SPLIT(SUBSTITUTE(A1,"+",","),","))
But this doesn't work because it's only counting the numbers as 1 item, and the COUNT function doesn't appear to work.
How can I make this work, so that it correctly gives the number of attendees as 11?
You can use the following formula
=IF(LEN(A2),
SUM(COUNTA(SPLIT(A2,",")),
IFERROR(SPLIT(REGEXREPLACE(A2,"\D"," ")," "))),"")
Functions used:
IF
LEN
SUM
COUNTA
SPLIT
IFERROR
REGEXREPLACE
You can obtain the total sum by doing this:
=if(regexmatch(A1,"\+"),sum(ArrayFormula(query(split(transpose(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0))),if(isblank(A1),"",counta(split(A1,","))))
Explanation:
if(regexmatch(A1,"\+"), something, if(isblank(A1),"",counta(split(A1,",")))) => if there are not + signs in the answer, then check if the cell is empty or not, if empty, print blank, else just count how many people are between commas, otherwise calculate with the plus ones. (explanation below)
split(A1,",")),"\+") => red area => will separate the cell by commas, and the result can be seen in the red area in the picture
split(TRANSPOSE(split(A1,",")),"\+") => green area => will loop through each of the results above and separate to a cell on the right the values that have a + sign between them, can be seen in the green area in the image
query(split(TRANSPOSE(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0) => blue area => then we will query the 2 columns, in the left one we want to count the number of rows in that column (the columns with the names), on the next column we want to sum the values (the plus ones)
sum(ArrayFormula(query(split(transpose(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0))) => yellow area => then we will sum the values of the 2 columns to get the final result
Related
Super new so please forgive me :-)
In Excel, I would have done an iterative sumif($a$1:a1) and then countifs( all the ones that say "1" vs. higher numbers:
example iterative
Blue 1
blue 2
green 1
red 1
purple 1
green 2
I have 2 tables(fields): FloorSamples(location,sku) and ItemData(sku, collection)
Here is the output I am looking for:
Collection #stores that have that collection
Since collections have multiple items to complete a group I receive this output instead:
Collection #items that have that collection label
If 12 locations have a collection, and there are 5 items per store that have that collection name, I would like it to return 12, not 60.
Assuming there is a many-to-one relationship between FloorSamples.sku and ItemData.sku, use this measure in a visual with Collections as a dimension (rows or axis), you will get what you're looking for.
DISTINCTCOUNT(FloorSamples[location])
Ok guys, I'm pretty basic here, so dum it down for me please!
Can you sum the total times text shows up in a list? I have a list of initials that are in two columns in two sheets actually, like this:
Sheet 2
Column E - Column F
OA, GK, EF ...... - PZ
...
Sheet 3
Column E - Column F
GK, IN, PZ..... - OA
...
and I want to tally the number of times each initial shows up for each person in their row in a master sheet 1?
I tried this & I used CNTRL + SHFT + ENTER, but the formula has some flaw:
=SUM(IF(ISTEXT(FIND("OA",'SHEET2!E:F))))+SUM(IF(ISTEXT(FIND("OA",'SHEET3!E:F))))
Wait, I figured it out...I guess I have to use COUNTIF instead of SUMIF, and I don't have to do all the fancy FINd or SEARCH stuff, I can just surround the criteria in stars!!
So, this worked:
=COUNTIF('Sheet2!E:F,"OA")+COUNTIF('SHEET3!E:F,"OA")
I cannot find a solution to my problem:
I have a sheet with ~290 rows and ~80 columns. The first row and column are fixed/header.
I would like to collect non-blank values and their header into column B.
I've tried to search for solutions, but I'm not as good at excel, so I cannot wrap my head around most of the advice that I've found.
In Google Sheets you could use an Array formula. I got this:
The formula I've used:
=ArrayFormula(CONCATENATE(IF(--(C2:G2<>"")*COLUMN($C$1:$G$1)<>0;$C$1:$G$1&" "&C2:G2;"")))
This is how it works:
(--(C2:G2<>"") will return an array of 0 and 1 if the cell is blank or not
COLUMN($C$1:$G$1) will return an array of column numbers of each cell
(C2:G2<>"")*COLUMN($C$1:$G$1) we multiply both arrays, so we will get an array of column numbers of non blank cells and 0 of blank cells
<>0;$C$1:$G$1&" "&C2:G2;"") We check if each number in the array obtained in step 3 is 0 or not. If it's 0, it returns a null value, if not, it returns the value of cell
CONCATENATE will concatenate all values from previous array (step 4) so we concatenate null values with real values of non blank cells.
Not sure if this will make the sheet load slower if you have too many records.
Hope this helps
Excel is not the same Google Sheets
=ARRAYFORMULA(TRIM(REGEXREPLACE(
TRANSPOSE(
QUERY(TRANSPOSE(IF(C2:F13<>"",C1:F1 & ", ","")),,99^99)
),
"((\s+)|(,\s*$))",
" "
)))
My sample
use:
=ARRAYFORMULA(REGEXREPLACE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
IF(C2:G<>"", C1:G1&" "&C2:G&",", )),,99^99))), ",$", ))
I have a spreadsheet set up with tv program titles in column B, the next 20 or so columns are tracking different information about that title. I need to count the number of blank cells in column R relating to the range in column B that contains titles (ie, up to the first blank row in column B.)
I can easily set up a formula to count the number of empty cells in a given range in column R, the problem is as I add more titles to the sheet I would have to keep updating the range in the formula [a simple =COUNTIF(R3:R1108, "")]. I've done a little googling of the problem but haven't quite found anything that fits the situation. I thought I would be able to get the following to work but I didn't fully understand what was going on with them and they weren't giving the expected results.
I've tried these formulas:
=ArrayFormula(sum(MIN("B3:B"&MIN(IF((R3:R)>"",ROW(B3:B)-1)))))
=ArrayFormula(sum(INDIRECT("B3:B"&MIN(IF((R3:R)>"",ROW(B3:B)-1)))))
And
=if(SUM(B3:B)="","",SUM(R3:R))
All of the above formulas give "0" as the result. Based on the COUNTIF formula I have set up it should be 840, which is a number I would expect. Currently, there are 1106 rows containing data and 840 is a reasonable number to expect in this situation.
Is this what you're looking for?
=COUNTBLANK(INDIRECT(CONCATENATE("R",3,":R",(3+COUNTA(B3:B)))))
This counts the number of non-blank rows in the B column (starting at B3), and uses that to determine the rows to perform COUNTBLANK in, in column R (starting at R3). CONCATENATE is a way to give it a range by adding strings together, and the INDIRECT allows for the range reference to be a string.
a proper way would be:
=ARRAYFORMULA(COUNTBLANK(INDIRECT(ADDRESS(3, 18, 4)&":"&
ADDRESS(MAX(IF(B3:B<>"", ROW(B3:B), )), 18, 4)))
or shorter:
=ARRAYFORMULA(COUNTBLANK(INDIRECT("R3:"&
ADDRESS(MAX(IF(B3:B<>"", ROW(B3:B), )), 18, 4))))
or shorter:
=ARRAYFORMULA(COUNTBLANK(INDIRECT("R3:R"&MAX(IF(B3:B<>"", ROW(B3:B), ))))
I want a function to subtract one number in a cell from another number on a different page and cell based on what word is in the cell next to the original number.
In the picture is a lista of expenses, so far only groceries is labeled, but the rest will be labeled with car loan, gasoline, clothes, and miscellaneous.
I need a function that will take my budgeted number (like 155 on the right), and compare it to all the words in column H. If a word like “gasoline” is found I want the function to subtract the value to the left of the key word.
New picture with updated progress
=ARRAYFORMULA(IF(H2:H="Groceries", J2:J-G2:G, ))
This code is making all of I return what subtracting any number with “Groceries” next to it by the value in its respective J cell. I only need I2 to change when a new “Groceries” key word is entered, and the value in its respective H cell should be subtracted from the J2 cell.
(https://i.stack.imgur.com/5ar6d.png)
try like this in I2 if it fits
=IF(H2="Groceries"; G2-J2; )
then you could enter the next level with using an array formula in I2
=ARRAYFORMULA(IF(H2:H="Groceries"; G2:G-J2:J; ))
for more words use regex like:
=ARRAYFORMULA(IF(REGEXMATCH(LOWER(H2:H);
"groceries|car loan|gasoline|clothes|miscellaneous"); G2:G-J2:J; ))