FILTER array and COUNTIF/loop counter - google-sheets

This is basically a continuation of my previous question. But my intended output is outlined in a sample Google Sheets:
https://docs.google.com/spreadsheets/d/1k1wQqATlhOuS_ztqtpz3FERVY-g-34rIDARbfOwdtV4/edit?usp=sharing
The intention is there is Control Number in Form Responses 1 Sheet COLUMN AC that serves as a tracker and a search key. Form submissions can add an update or close that Control Number which is indicated in COLUMNs B and C. I would like to add a number appended to UPDATE TICKET in COLUMN B entries when they are filtered and added to a collated data entry similar in Sheet 1.
My problem arises when using COUNTIFS or COUNTIFS since the general forumula in Sheet 1 has dissimilar array sizes (and thus a CONCAT error) and the COUNTIF does not count the per element of the filtered array (in the sample sheet, it only appends 2 to all entries.
=arrayformula(filter('Form Responses 1'!$B2:$B,'Form Responses 1'!$C2:C=INDEX('Form Responses 1'!$C2:$C,COUNTA('Form Responses 1'!$A2:A),0))&" "&IFERROR(COUNTIF(filter('Form Responses 1'!$B2:$B,'Form Responses 1'!$C2:C=INDEX('Form Responses 1'!$C2:$C,COUNTA('Form Responses 1'!$A2:A),0),'Form Responses 1'!$B2:$B="UPDATE TICKET"),filter('Form Responses 1'!$B2:$B,'Form Responses 1'!$C2:C=INDEX('Form Responses 1'!$C2:$C,COUNTA('Form Responses 1'!$A2:A),0),'Form Responses 1'!$B2:$B="UPDATE TICKET")),"")&":"&" "&filter(TEXT('Form Responses 1'!$H2:$H,"dd/mm/yyyy HH:mm"),'Form Responses 1'!$C2:C=INDEX('Form Responses 1'!$C2:$C,COUNTA('Form Responses 1'!$A2:A),0))&char(10))
I also tried adding COUNTIFS additonal rule condition such as row(filteredarray),=<row(filterearray) to output the intedend counter 1,2,3, etc. per match (similar to how the control number works) of the UPDATE TICKET but the ROW function doesn't seem to accept filtered array as a cell reference. Lastly, I want to omit the counter on the last entry which is a CLOSE TICKET. I detailed my trials and the intended output in the linked Google Sheets.

It was difficult to follow what you'd done so far, but you were clear with your goal, so i redid what I needed to to get there. Any formulas in yellow are mine. You'll find this solution on the tab called MK.Help in cell A2.
=ARRAYFORMULA(SUBSTITUTE(TRIM(SPLIT(TRANSPOSE(QUERY(MID(QUERY({"00000"&Form!C2:C&Form!AD2:AD&":|",TEXT(ROW(Form!A2:A),"00000")&Form!AE2:AE&": "&TEXT(IF(Form!H2:H,Form!H2:H,Form!A2:A),"m/d/yy h:mm")&CHAR(10)&CHAR(10),Form!B2:B},"select MAX(Col2) where Col3 is not null group by Col2 pivot Col1"),6,100),,9^9)),"|")),CHAR(10)&" ",CHAR(10)))

Form Reponses 1 - AE2
=ArrayFormula(IF(C2:C="",,"UPDATE TICKET "&COUNTIFS(C:C,C2:C,ROW(A:A),"<="&ROW(A2:A))&": "&TEXT(A2:A,"dd/MM/yyyy HH:mm")))
Sheet1
=ArrayFormula(REGEXREPLACE(REGEXREPLACE(SPLIT(TRANSPOSE(QUERY(QUERY(FILTER({'Form Responses 1'!C:C&"♥",'Form Responses 1'!AE:AE&"♦"},'Form Responses 1'!B:B="UPDATE TICKET"),"select max(Col2) where Col2 is not null group by Col2 pivot Col1",),,10^7)),"♥"),"(?:^\s*)|(?:\s*(♦)\s*)|(?:♦\s*$)","$1"),"♦",CHAR(10)))

Related

How to 'count' only when header matches value?

I have a Google Form that collects a bunch of data from dropdown questions on a Sheet with each question going to one column (as normal). On separate sheets, I want to be able to count how many times each option is selected.
Here is an example of what the response sheet might look like. A, B, and C are all questions.
I would then have separate sheets for 'Person?', 'Place?', and 'Thing?'. The 'Person?' sheet would look something like this:
I want to be able to add in the count of each time the option appears for that question. In the example, notice that 'Napoleon" is in both Col A and Col C. If I just count the number of times 'Napoleon' appears, I will get '2' even though he only appears once in the "Person?" responses.
I originally used a QUERY function like =QUERY('Input Data'!1:1000, "select count(A) where A contains '"&$A2&"'",0). BUT, I need it to be dynamic. So the "Person?" question may not always be Col A. I want the Query (or whatever formula) to search the headers and only return the count of that option for that question even if the column location changes.
Okay, I figured it out! In case someone else is curious, I used this formula:
=QUERY({'Input Data'!A1:L}, "SELECT COUNT(Col"&MATCH("Person?", 'Input Data'!1:1,0)&") WHERE Col"&MATCH("Person?", 'Input Data'!1:1,0)&" CONTAINS '"&$A2&"' label COUNT(Col"&MATCH("Person?", 'Input Data'!1:1,0)&") ''",0)
Lee, I sent you a PM about your most recent post, but in the process, I came across this one. There is no need for multiple formulas or manual entry references. One formula can produce the entire report with headers, listing and counts:
=IFERROR(QUERY(FILTER(FILTER(A:L,A:A<>""),A1:L1="Person?"),"Select Col1, COUNT(Col1) GROUP BY Col1 ORDER BY Col1 LABEL COUNT(Col1) 'Count'",1),"No Matches")
Just fill in the header your looking for between the quotes where Person? is now.
The double FILTERs mean "Start with only rows where Col A is not null and Row 1 reads 'Person?'"
Then QUERY simply returns the unique names in the left column and their counts in the right column. Because the QUERY had a final parameter of 1, any existing header will be kept (in this case, the one you were searching for); and the created column will receive a header (i.e., LABEL) of Count.
IFERROR will give a friendly error message if no matches are found (in which case check that what you entered for the search in the formula exactly matches a column header in the range).

Google sheets question - filter sum equation

I have a list of email addresses in one sheet (first column).
I have a list of transactions in another sheet with emails and sale amounts.
I am looking for a formula that adds up all the transaction $ sales for any transactions made by the people (emails) in the first sheet.
Any help would be much appreciated!
Your sample data is very limited (only one row matching one person, in fact). But the following formula should work for you. Place it in a new sheet, in cell A1:
=ArrayFormula(IFERROR({"Name","Total"; QUERY(FILTER(Transactions!A2:D,NOT(ISERROR(VLOOKUP(Transactions!A2:A,Tags!A:A,1,FALSE)))),"Select Col2, SUM(Col4) GROUP BY Col2 ORDER BY Col2 LABEL SUM(Col4) '' ")},"No Data"))
This one formula will produce the headers (which you can change within the formula itself as desired) and all results.
FILTER filters in only 'Transactions' data (names through amounts) where the emails are found in the 'Tags' sheet.
Then QUERY returns the name and totals for each match in alphabetical order by name.
If there are no matches, "No Data" will show instead.
If I understood your question correctly!
Try this on the sheet, where you only have emails and wanted to get sum of sales amount
=sumifs(range_whichHasTransaction , range_of_Email_inThat_TransactionsTable , Cell_Reference_ofEmail_forWhich_you_want_sum_the_Transaction_Amount)
it will Look something like this:-
sumifs(TransactionSheet!B:B,TransactionSheet!A:A,Emails!A2)
Reference
SUMIFS

Google Query Function Incorrectly Filtering Data

I am having an issue where Google Query is incorrectly filtering columns based on data values in a specific column.
The link to an example of the issue is here.
On the "Roster" tab in the highlighted red cells, there is a cell formula that queries the "Database" tab. There should be no returned values as it says no rows with "PL" in Col1 except it returns a row with "PL" in Col1. What could be the reason for this?
Most of the data has been cleared for privacy reasons and replaced with John Doe however on duplicate copies of this the query works but on this version, it does not work.
what you experience is the result of not defining the 3rd parameter in QUERY syntax that defines the number of header rows. by skipping it QUERY obeys selective implementation, in other words, it decides on its own to account in header rows or not based on the dataset.
=QUERY(SORT(Database!$D$2:$M, Database!$G$2:$G, 1, Database!$M$2:$M, 1),
"select Col8 where Col1<>'PS' and Col1<>'PL' and Col3='2'", 0)

Query and ImportRange with Dynamic Values

I have 2 sheets which are connected.
Sheet-1: Has ID column and Status column (Status field is manually updated by the team)
Sheet-2: Has ID column and Status column (+ many other fields)
Requirement: Status column in Sheet 2 to be updated from Sheet-1 if ID column in sheet-2 = ID column in Sheet-1
I wrote a Query and ImportRange, but I could find Query working only when I compare it against a static value (for e.g. Yes). What I want is it to check against the value in ID column from both the sheets and import only for rows that match.
=QUERY(IMPORTRANGE("1ZkPaYb1IIIkcbVerdmZ-Ru1vxFu1YMWj74QNQj2jles", "Ops Action Sheet!B2:B10000"),"select Col2 where Col1 = 'Yes'")
This doesn't directly answer your question about using QUERY, but I believe that that function might not be the best tool for what you're trying to do.
I write below a solution using the alternative function VLOOKUP.
I am assuming here that by "Sheet-1" and "Sheet-2", you actually mean entirely different spreadsheets, judging by your use of IMPORTRANGE.
If you don't mind having a copy of Sheet-1's contents living within Sheet-2, here is what you can do:
On a new sheet (tab) in Sheet-2, copy this function (fill in sheet_1_url):
=IMPORTRANGE("sheet_1_url", "Ops Action Sheet!$A:$B")
You should see a copy of the data from Sheet-1 in that tab. You can hide this tab or protect it if you wish.
On your main data tab within Sheet-2, copy this formula in your Status column (assuming that your ID is in A2:
=IFERROR(VLOOKUP($A2,range_from_step_1,2,),)
Copy that formula down as much as you need.
However, if you don't want to have a copy of Sheet-1's data in Sheet-2 for whatever reason, you can simply skip steps 1-2 above, going straight to step 3, with the following formula in Sheet-2:
=IFERROR(VLOOKUP($A2,IMPORTRANGE("sheet_1_url", "Ops Action Sheet!$A:$B"),2,),)
Not that I recommend it, since you'd technically be importing your data virtually within the formula N number of times, which will be a huge performance hit.
You can see the references for the formulas used above here:
IMPORTRANGE
VLOOKUP
IFERROR
edit to reflect and paste in spreadsheet 2:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, IMPORTRANGE("ID", "Sheet!A:C"), {2, 3}, 0)))
A2:A - column of IDs in spreadsheet 2
Sheet!A:C - column A of this range hosts IDs
{2, 3} - brings column B and C from spreadsheet 1 into spreadsheet 2

Display Rows From Another Sheet Based On Range Of Dates

I'll try to explain this as best as I can, I'm not super experienced with spreadsheet formulas so bear with me.
Currently I have 2 Google spreadsheets, one contains a list of all client related tasks. The second spreadsheet is client specific, it has a few sheets such as "Feeder", "Archived Requests", "Monthly Report". The "Archived Requests" sheet lists all the data assigned to a specific client from my first spreadsheet using QUERY IMPORTRANGE:
=Query(IMPORTRANGE("key","spreadsheet-name!A:Z"),"Select Col2, Col3, Col4, Col5 where Col1 contains 'TOSC'",1)
This part works all fine and good.
My "Feeder" sheet lists some =DATE and =EOMONTH formulas which I have made into Named Ranges.
What I'd like to do, ideally, is display all data from the "Archived Requests" sheet on the "Monthly Report" sheet between the named range "ReportMonthStart" and "PriorMonthStart".
Essentially, what I'm hoping to achieve is a dynamic listing of row data that goes back 30 days from the 15th of each month.
I'm not sure if this should/can be done with a Query or a Filter, or any other formula.
Here is the link to my current spreadsheet.
The filter does this nicely:
=filter('Archived Requests'!A2:E, ('Archived Requests'!A2:A >= PriorMonthStart) * ('Archived Requests'!A2:A <= ReportMonthStart))
This returns A-E entries of the rows where A column is between PriorMonthStart and ReportMonthStart. Multiplication of two conditions is logical AND.

Resources