Counting elements that contain colons in Google Sheets - google-sheets

I'm trying to count bus headways --the number of minutes between bus arrivals--in Google Sheets. The arrivals are written as 0:00, 1:00,2:00, etc... I want to count the number of instances of zero-minute buses, one-minute buses, etc..
When I try this =countif(range,"0:00"), I get "0:00" as an answer. What am I doing wrong?

Change the formatting of the range to text and then try
=countif(range, "*:00")

Maybe try using a Pivot Table:

One option is to use a helper column along with ISNUMBER and SEARCH.
Let's say your data is in A1:A3. In B1, you could put =ARRAYFORMULA(IF(ISNUMBER(SEARCH(":",A1:A))=TRUE,1,"")).
That searches for ":" in column A. If the statement evaluates to TRUE then a 1 is placed in the corresponding row. If it evaluates to FALSE then nothing "" is entered.
Then in C1 you could put =SUM(B1:B).

Related

COUNTIF with IMPORTRANGE result keep showing only 0 or 1? WHY?

I have one spreadheet that includes name, id and amount of numbers data in it and i want to make the report in other spreadsheet.
i want to count the name column that is not blank, so i type this
=COUNTIF(importrange("gsheet link","Payroll 16-31 Jan!B3:B"),"<>")
but the result is "1" in fact that there are 3670 names on the column
=COUNTIF(importrange("gsheet link","Payroll 16-31 Jan!B3:B"),"<>"&"")
but still not working
can someone help?
I want to get the exact calculation of those data
Two things: have you connected the spreadsheets? If not, use IMPORTRANGE outside COUNTIF, something like =importrange("gsheet link","A1") . Accept the permissions and see if COUNTIF now does it right
If it doesn't, try with COUNTA that is specifically defined for counting non blank cells:. =COUNTA(importrange("gsheet link","Payroll 16-31 Jan!B3:B"))

Unnest two columns in google sheet

I have a table like this one here (basically it's data from a google form with multiple choice answers in column A and B and non-muliple choice data in column C) I need a separate row for each multiple choice answer.
Column A
Column B
Email
A,B
XX,YY
1#gmail.com
A,C
FF,DD
2#gmail.com
I tried to un-nest the first column and keep the remaining columns like this
enter image description here
I tried several approaches I found with flatten and split with array formulas but I don't know where to start really.
Any help or hint would be much appreciated!
You can use the split function on the column A and after that, use the index function. Considering the table, you can use:
=index(split(A2,","),1,1)
The split function separate the text using the delimiter indicated, returning an array with 1 line and 2 columns; the index function will return the first line and the first column from this array. To return the second element from the column A, just change to
=index(split(A2,","),1,2)
I think there's no easy solution for this. You're asking for as many combinations of elements as multiple-choice elections have been made. Any function in Google Sheets has its potentials and limitations about how many elements it can express. One very useful formula here is REDUCE. With REDUCE and sequences of elements separated by commas counted with COUNTA, you can stablish this formula:
=QUERY(REDUCE({"Col A","Col B","Email"},SEQUENCE(COUNTA(A2:A)),LAMBDA(z,c,{z;LAMBDA(ax,bx,
REDUCE({"","",""},SEQUENCE(ax),LAMBDA(w,a,
{w;
REDUCE({"","",""},SEQUENCE(bx),LAMBDA(y,b,
{y;INDEX(SPLIT(INDEX(A2:A,c),","),,a),INDEX(SPLIT(INDEX(B2:B,c),","),,b),INDEX(C2:C,c)}
))})))
(COUNTA(SPLIT(INDEX(A2:A,c),",")),COUNTA(SPLIT(INDEX(B2:B,c),",")))})),
"Where Col1 is not null",1)
Since I had to use a "initial value" in every REDUCE, I then used QUERY to filter the empty values:

Google Sheets - Filtering out values in a range from another range

-- EDIT #2 -- Updated the Google Sheet again with a solution which is painfully close. Best formula I've had so far is below. --
=ARRAYFORMULA(SPLIT(UNIQUE({ARRAYFORMULA(QUERY(IF(COUNTIF(G4:G&"|||"&H4:H,ARRAYFORMULA(A4:A&"|||"&B4:B))>0,REGEXREPLACE(A4:A&"|||"&B4:B,".*",""),A4:A&"|||"&B4:B),"SELECT * WHERE Col1 IS NOT NULL"));ARRAYFORMULA(QUERY(IF(COUNTIF(G4:G&"|||"&H4:H,ARRAYFORMULA(D4:D&"|||"&E4:E))>0,REGEXREPLACE(D4:D&"|||"&E4:E,".*",""),D4:D&"|||"&E4:E),"SELECT * WHERE Col1 IS NOT NULL"))}),"|||"))
-- EDIT -- Updated the Google Sheet to more closely reflect my use case --
Pretty confident someone's asked this before but I've been Googling for a few hours now and I'm starting to lose hair. I think I've got to use a QUERY function but not 100% on that.
Demo sheet here: https://docs.google.com/spreadsheets/d/1p_hqk9WydcyXQZT4bIm4DSZZnaPKbngtnZ0-laYHwk8/edit?usp=sharing
What I want to do:
I want to combine the ranges under DATA 1 and DATA 2, but I want to exclude and rows which start with the values in DATA 3.
RESULT 1 doesn't add value but shows how I was adding DATA 1 and DATA 2 together.
RESULT 2 shows the result I'm trying to get.
RESULT 3 hidden but where I got to (and doesn't add value again, sorry). I can get it mostly working, but I'd have to manually specify in the QUERY which combinations I'm looking for... and frankly my dataset is HUGE. That formula currently looks like this:
=QUERY(UNIQUE({FILTER(A4:B,NOT(ISBLANK(A4:A)));FILTER(D4:E,NOT(ISBLANK(D4:D)))}),"SELECT * WHERE NOT Col1 STARTS WITH 'a' OR NOT Col2 STARTS WITH 'v'",-1)
Hope someone can help me out! You're my only hope.
This works for your example data. It uses ARRAYFORMULA and MATCH to concatenate the two columns and LEFT to only use the first character in the match function. You might need to find a slightly smarter way to do the starts with element depending on your actual data.
=UNIQUE({FILTER(A4:B,not(isblank(A4:A)),iserror(MATCH(ARRAYFORMULA(A4:A&left(B4:B,1)),ARRAYFORMULA(G4:G&H4:H),0)));FILTER(D4:E,not(isblank(D4:D)),iserror(MATCH(ARRAYFORMULA(D4:D&left(E4:E,1)),ARRAYFORMULA(G4:G&H4:H),0)))})
Documentation:
MATCH: here
ARRAYFORMULA: here
Was also looking for how to find the set-difference between two ranges.
All my values were in one range but I reworked my solution to fit your case of needing to join ranges too.
Finding the set-difference between two ranges:
// given A1:A9 and C1:C9
// return all values in A1:A10 excluding those in C1:C10
=filter(A1:A9, not(iferror( match(A1:A9,C1:C9,0), false )), A1:A9<>"")
Finding the set-difference between two joined ranges and a third range:
// given A1:A9, B1:B9, and C1:C9
// return all values in A1:A10 and B1:B10 excluding those in C1:C10
=filter({A1:A9;B1:B9}, not(iferror( match({A1:A9;B1:B9},C1:C9,0), false )), {A1:A9;B1:B9}<>"")
Breakdown:
Goal is to get an output range that is the input range excluding all values in an "exclusion" range
MATCH: match all values that are in both your input range and your exclusion range (remaining values will produce an error)
NOT + IFERROR : convert matches to false and errors to true
FILTER: filter the input down to only the true values (i.e. whats not matched, a.k.a. remove the excluded values), and also add a 2nd condition to remove blanks
tips:
{X;Y}: unions two ranges, ; adds rows , adds columns
X<>"": true for all non-blank values in range X

Check if data that satisfies multiple criteria exists in both sheet 1 and sheet 2

My table contains 2 sheets with a different number of columns. I want to add a column that will display true or false (or any other 2 opposite values ) for each row depending on whether this row satisfies 2 criteria which are: sheet1!col1=sheet2!col1 and sheet1!col2=sheet2!col2.
You'll find an illustration below.
I've tried using
ARRAYFORMULA(VLOOKUP(A1&B1, {Sheet1!A1:A4&Sheet1!B1:B4,Sheet1!C1}, 3))
but I get an error message
vlookup evaluates to an out of bound range
So I wanted to try
QUERY({Sheet1!A1:B4,A1:B5}, "Select C where ")
but I couldn't figure out how to write the condition where (sheet1)col1=(sheet2)col1 & (sheet1)col2=(sheet2)col2 and I also don't know if I can work with tables of different dimensions. I finally tried
=MATCH(A1&B1,{Sheet1!A1:A&Sheet1!B1:B})
but it always returns 1.
Any idea please?
Sheet 1
Sheet 2
Your first formula is almost right. You are getting the error message because there is only one column in the curly brackets so you have to change it to
=ArrayFormula(vlookup(A1&B1,{Sheet2!A:A&Sheet2!B:B},1,false))
and add the 'false' to make sure it only does exact matches.
To make the query work you need the right syntax to access cells in the current sheet:
=query(Sheet2!A:B," select A,B where A='"&A1&"' and B='"&B1&"'")
To make the match work, you need to enter it as an array formula and add a zero to specify exact match:
=ArrayFormula(MATCH(A1&B1,{Sheet2!A:A&Sheet2!B:B},0))
However I would take flak from my colleagues if I didn't point out that there is an issue with the vlookup and match as shown above - toto&moto would match with not just toto&moto, but also with tot&omoto etc. The way round this is to add a separator character e.g.
=ArrayFormula(vlookup(A1&"|"&B1,{Sheet2!A:A&"|"&Sheet2!B:B},1,false))
=ArrayFormula(MATCH(A1&"|"&B1,{Sheet2!A:A&"|"&Sheet2!B:B},0))
These still need some tidying up if they are to report Yes and No, and also not to give false positive on blank rows - also the vlookup and match can be written as self-expanding array formulas - but that is the short answer to the question.

Google Spreadsheet Function That Sums Numbers In A Column When the Row Contains An EXACT Text

I've been at this problem for a while now. I am trying to sum numbers under a specific column when the rows equal a certain text and then display that sum on a different sheet. So far I came up with this formula: =IF(EXACT(A2,Table!A2:A)=TRUE,SUM(Table!C2:C)); however the only problem is that is sums everything in column C (which makes sense).
I wish there was a way to do something like the following: SUM(Table!C2:C where EXACT(A2,TABLE!A2:A)=TRUE). I've also tried the SUMIF(), DSUM(), and QUERY() functions to no avail. I must be getting logically tripped up somewhere.
Figured it out: =SUM(FILTER(Table!E4:E, EXACT(Table!A4:A,A4)=TRUE)).
=sum ( FILTER (b1:b10, a1:a10 = "Text" ) )
// the above formula will help you to take the sum of the values in column B when another column A contain a specific text.
The formula is applicable only in Google Spreadsheets

Resources