Count data between two data ranges - google-sheets

I've spent countless hours trying to count this data between two date ranges. I'm using a formula I've previously used in the past, but with no luck.
(Fixed - Sample Data - see updated Actual Data below, formula is not working with actual data)
Current Formula vs. Expected Results
=Query(flatten(filter(E3:E11,D3:D11>=D16,D3:D11<=E16)), "Select Col2,count(Col2) where (Col2 is not null) group by Col2 label count(Col2)''",)
I've tried:
COUNTIFS but could not find how to include criteria.
Using INDIRECT with named range in the 'Expected Results' Reason 1 - Reason 5 Column and COUNTIFS in the column to the right.
Googling over 50+ different sites and formulas.
(Updated: Actual Data) (Error - Not working)
[Current Formula and Empty Result]
(https://i.stack.imgur.com/SnRkm.png)
The actual data is being pulled from the Data sheet. The data on this sheet looks like this
Data on the Data sheet that's pulled onto the date filter sheet
(https://i.stack.imgur.com/yZNh9.png)
and is using this formula:
=ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(O11:O, ","))="",,TEXT(J11:J,"MM/DD/YYYY")&"×"&L11:L&"×"&M11:M&"×"&N11:N&"×"&SPLIT(O11:O, ","))),"×"),"where Col2 is not null")))

Solution:
I used the same code I previously used. However, the dates that were being selected could not be selected with the data that was being pulled.
I used:
=INT(O3)
to copy the date into another column, dragged the formula down, and used the filter to select the date from this new column. The date filter then worked.

Related

Use dynamic created Query text as a Query formula in Google Sheets [duplicate]

This question already has answers here:
Stacking Multiple Arrays In Query/Lambda Function
(2 answers)
Closed 3 months ago.
First of all this is my first question here...
Ok, and now my problem:
I created a formula that generates a dynamic Query if you are searching for data in multiple sheets. I just write the names of the sheets in green field and it changes the Query.
The text for the Query is correct, but now I want this to by the actual formula in a cell to display the data.
If I use the = and add the cell with the Query text, it copy the text. I tried the INDIRECT formula, but it does the same.
How can I use a this dynamic text to be my Query to dispaly the data depending on the amount of names in the green field?
EDIT: As advised by user doubleunary (as mentioned, this is my first time), I'm going to rephrase the problem.
In an spreadsheet a manager imputs for every task the amount a worker has made. He creates an new sheet for each date and imputs the data for that day. Each day can have different rows of data. The boss wants a spreadsheet that display in one sheet all that has been done in the current month. I used Query because you can easy join data from multiple sheets and ignor the empty rows.
But the problem is, that every day a new sheet is added with a new "name" (date). And the easyest way I found tho make a dynamic Query, without the Boss to manualy edit the Query, was to create a text with TEXTJOIN formula, in witch he ony needs to enter the new "name" (date).
If there is a better was, please share, but it should not be in App Script if possible.
Thank you.
Easily you can't transform a text into a formula.
In this case, you should create the query formula and insert the ranges with Indirect function, like this:
=Query({Importrange(LINK,Indirect("'"&O4&"'!I38:S107"));Importrange(LINK,Indirect("'"&O5&"'!I38:S107"))},"Select * Where Col1 is not null",0)
If the formula you quote and the data sheets are all in the same spreadsheet file, you should not to use importrange() but indirect(), like this:
=query(
{
indirect(O4 & "!I38:S107");
indirect(O5 & "!I38:S107")
},
"where Col1 is not null",
0
)
In the event the row references such as I38:S107 change from time to time as well, you can put those references in a cell and refer to them the same way.
try (assuming url is same for all sheets):
=QUERY(LAMBDA(x, QUERY(REDUCE(SEQUENCE(1, 11), x,
LAMBDA(a, c, {a; IMPORTRANGE("url", c"!I38:S107")})),
"where Col1 is not null", 1))
(O4:INDEX(O:O, MAX((O:O<>"")*ROW(O:O)))), "offset 1", )
more examples: https://stackoverflow.com/a/74280310/5632629

Get last value of selected row in Google Sheets

I am trying to automatically find the last column in the current row with values. I want to do this because some rows have more columns than others. Here is the
Spreadsheet I am taking data from
.
Here is the query I have right now. I am getting circular dependency issues.
=QUERY(IMPORTRANGE("redacted_link","PriceList!A1:AZ100000"), "Select "&IFERROR(LOOKUP(9^9,(INDIRECT("R[0]C1", FALSE)):(INDIRECT("R[0]C50", FALSE))))&" where Col1 = '"&(INDIRECT("R[0]C1", FALSE))&"'",1)
This part: where Col1 = '"&(INDIRECT("R[0]C1", FALSE))&"'",1) already works and is effective at getting the value of column 1 in the current row.
&IFERROR(LOOKUP(9^9,(INDIRECT("R[0]C1", FALSE)):(INDIRECT("R[0]C50", FALSE))))&
I think this is referencing the current file instead of the spreadsheet I am taking data from.
try:
=INDEX(REGEXEXTRACT(TRIM(FLATTEN(QUERY(TRANSPOSE(IMPORTRANGE(
"id", "PriceList!A1:AZ100000")),,9^9))), "\d+(?:.\d+)?")*1)

Query importrange HUGE multiple sheets and turns out error

so I have 5 separate google sheets, each one with the same title and format enter image description here.
There are 8000-10000 rows each so far, as it's a daily sales updating data, yearly may finish with 20000-40000 rows each.
So what I want to do is to merge all of them into another single sheet, and I've tried the following formulas:
enter image description here
Formula A
={IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3);IMPORTRANGE(B4,C4);IMPORTRANGE(B5,C5);IMPORTRANGE(B6,C6)}
Results:
#VALUE!
"In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Formula B (reduced the data to only one month)
=QUERY({IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3);IMPORTRANGE(B4,C4);IMPORTRANGE(B5,C5);IMPORTRANGE(B6,C6)},"SELECT * Where Col2 > DATE'2022-5-1' AND Col2 <= DATE'2022-5-31' ",0)
Result:
#VALUE!
"In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."
Formula C (check if is the problem of the code)
={IMPORTRANGE(B2,C2);IMPORTRANGE(B3,C3)}
Results:
It works.
So my question is that, there is anyway via google sheet let me merge all the 5 sheets in one (5sheets*40000rows into one sheet) , or it's not the place to manage that volumn of data?
every importrange needs to be run separately before you use it in your joint formula. the array error you are getting is a result of some importranges importing those 7 columns and those importranges that are not connected output one single cell. make sure you allow access to all your importranges.

Combing base data set for a formula from two *other* Google sheets

We have hit the dreaded 5 million rows limit which is so small for any semi-serious data.
We have an important ArrayFormula piece in one of our worksheets (tab) currently that summarizes the data from another worksheet in the same file where time series data is kept with dates. This is our current function:
=ArrayFormula(SUMIFS(DataSheet!$B:$B,
MONTH(DataSheet!$A:$A), 1,
YEAR(DataSheet!$A:$A), 2020)
)
Explanation: This basically summed all of column B in the DataSheet tab for the month of Jan 2020 based on date found in column A of that sheet.
However, this worksheet of data that is now running close to that row limit. We can move it to another Google Sheets file, and refer to the same data via IMPORTRANGE.
The question then is how to refer to that data instead of the DataSheet!$A:$A in the above old formula? Will this reference be replaced by the entire IMPORTRANGE function?
Old:
=ArrayFormula(SUMIFS(DataSheet!$B:$B,
MONTH(DataSheet!$A:$A), 1,
YEAR(DataSheet!$A:$A), 2020)
)
New:
=ArrayFormula(SUMIFS(IMPORTRANGE(filename, rows)!$B:$B,
MONTH(IMPORTRANGE(filename, rows)!$A:$A, 1,
YEAR(IMPORTRANGE(filename, rows)!$A:$A, 2020)
)
This does not work of course, because we cannot have the exclamation ! followed by the column in an importrange. Any other thoughts?
Try this in cell A1 on a fresh, brand new tab somewhere:
=ARRAYFORMULA(QUERY(1*TEXT(IMPORTRANGE("[spreadsheet key]","Sheet1!A:B"),{"mmmyyyy","0.00"}),"select Col1,SUM(Col2) where Col2<>0 group by Col1 order by Col1")
The "spreadsheet key" is the combination of letters and numbers after the "/d/" and before the "/edit..." in the URL of your source sheet.
Obviously, you'd also replace "Sheet1!A:B" with whatever the real tab/column reference is.
Then, select all of Column A and from the Menu choose Format>Number>More Formats>Custom Number Formatting, Then this in the dialog box:
mmmm yyyy
You want to IMPORTRANGE from two different sheets in a different spreadsheet.
While the following formula will import data from both sheets, it will also import the blank rows, so you might have to scroll down hundreds of rows in order to see the data from the second sheet (and this might give your the wrong impression that the second sheet is not getting imported):
{
IMPORTRANGE("SPREADSHEET_ID","CurrentMonth!$A:$J");
IMPORTRANGE("SPREADSHEET_ID","All2020!$A:$J")
}
You can use QUERY in order to filter out blank rows:
=QUERY(
{
IMPORTRANGE("SPREADSHEET_ID","CurrentMonth!$A:$J");
IMPORTRANGE("SPREADSHEET_ID","All2020!$A:$J")
},
"SELECT * WHERE Col1 IS NOT NULL ORDER BY Col1 DESC"
)
Note:
I thought you'd like to sort the data according to the date in column A, please remove ORDER BY Col1 DESC if that's not the case.

Google Sheets Query returning results that don't exist in the source list

I am creating a budget tracker within Google Sheets. I am having trouble with Google Query Language returning results that do not exist in the source data
I have a Google Form into which expenditure can be entered, which populates an associated Sheet in my Google Drive. My Master budget tracker also sits within my Google Drive. I use IMPORTRANGE to pull the data into the Master from the Responses spreadsheet, and then Query to separate this out into different 'expenditure' categories on sheets within the workbook (one for each month). February worked perfectly - all expenditure was found and summed correctly and then the February sheet was duplicated for each month of the year, the formulae or look up terms updated. But March is acting strangely - it is returning a value for March that doesn't exist - and not only does the summed value not exist but the word 'March' also does not exist either, so shouldn't be matching. I have tweaked the code, tried refreshing and rewriting the formula into the cell to force a refresh, re-imported the range from the external spreadsheet, I have tried various parentheses placements (I'm not a SQL or Google Query Language expert, so am feeling my way a bit) as I thought it was something to do with the AND/OR clauses not being 'collated', but none has produced even a different result, it's always the same false value being returned
The query code is as follows:
=query(spend, "select sum(B) where H = '"&$H$1&"' and E='Leisure' or E='Tickets' or E='Parking' or E='Other' label sum(B) ''", -1)
'spend' is the range containing the data imported from the Responses spreadsheet, which includes several post form completion formulae coding the row with a day and a month. Right now, there are only values coded as 'February' in H - nothing else. Cell H1 contains the month name (written in, not formula). This formula works perfectly within the 'February' sheet, and if I update cell H1 to read 'February' in the March sheet it shows the accurate values for February, however, if I enter 'March' in H1 I am getting the odd outcome
I am expecting a £0 result for March, but instead, I am getting a value of £19.46. As previously described - the source list 'spend' only contains values coded as February in H, and the value £19.46 does not appear singularly in the list (and doesn't appear to be made by any values when 'summed'). I am at a loss as to what is happening, and no answers seem to address the appearance of mystery values, so I hope I'm not repeating old ground - please do correct me if I am, and many thanks in advance for any guidance
you picked 19.46 because even if H1 wasn't found in Query, Query continued to evaluate for AND and OR statements and sum up a bunch of nonsense
=IFERROR(IF(QUERY(spend,
"select count(H)
where H='"&$H$1&"'
label count(H)''", 0)>0,
QUERY(spend, "select sum(B)
where (H='"&$H$1&"')
AND (E='Leisure')
OR (E='Tickets')
OR (E='Parking')
OR (E='Other')
label sum(B)''", -1), ), )
I think you might just want to try this:
=query(spend, "select sum(B) where H = '"&$H$1&"' AND (E='Leisure' OR E='Tickets' OR E='Parking' OR E='Other') label sum(B) ''", -1)
EDIT: This will cause an error since it will return an empty query, so try this instead.
=iferror(query(spend, "select sum(B) where H = '"&$H$1&"' AND (E='Leisure' OR E='Tickets' OR E='Parking' OR E='Other') label sum(B) ''", -1),0)

Resources