Google sheets Arrayformula and Min question - google-sheets

I am writing this formula but it's not working, could someone help me please
=Arrayformula(min(FILTER('Sheet1'!F:F,'Sheet1'!H:H = "No",'Sheet1'!D:D=A2:A)))

I have added a new sheet ("Erik Help") to your sample spreadsheet. The following formula in D2 is highlighted in green:
=ArrayFormula(IF(A2:A="",,IFERROR(VLOOKUP(A2:A,SORT(FILTER(Sheet1!A:C,Sheet1!E:E = "No"),3,1),3,FALSE))))
You'll notice there is no MIN here.
Instead, I created a FILTER of Sheet1!A:C (not just C:C), SORTed this so that prices run from smallest to greatest (i.e., minimum prices at the top), then performed a VLOOKUP for each ID. Since VLOOKUP only returns the first match it finds, it will always return the minimum (if the ID is found in the FILTERed set; otherwise, null is returned by IFERROR).

While waiting for the arrayformula/min/filter answer, you might want to try query for the mean time:
I have also made some assumptions on other columns as well. Neglect both B and C if you don't have a need of them right now.
Formula:
Column B:
=arrayformula(ifNA(vlookup(A2:A&D2:D, {Sheet1!A2:A&Sheet1!C2:C,Sheet1!F2:F}, 2,0),"") )
Column C:
=arrayformula(if(isblank(D2:D), "", vlookup(A2:A&B2:B&D2:D, {Sheet1!A2:A&Sheet1!F2:F&Sheet1!C2:C,Sheet1!D2:D&" - "&Sheet1!E2:E}, 2, 0)))
Column D:
=query(query(Sheet1!A2:E, "select min(C) where E = 'No' group by A"), "offset 1", 0)
Given that the headers in Sheet1 are the following:
Output:
Note:
D is dependent on A
B is dependent on A and D
C is dependent on A, B, and D

Related

Can I use COUNTIF to count text strings in a range that exist within, or match, a single cell?

For this question I have made a simplifed example spreadsheet to illustrate what I am trying to achieve.
This can be found here.
https://docs.google.com/spreadsheets/d/1qbzuDHfRnGHkDhrcQWbQxRVcxsqo3MlJ3pZtU16nq7w/edit?usp=sharing
I will give background on the sheet first and then explain the problem, Forgive me if it's a bit convoluted it's my first time asking a question on here.
In the left hand side table I have example bank transactions made. In the right hand side table I have example data from my cash flow forecast. The goal is to match bank references and amounts to make sure that the forecast and the real transactions match up.
Actual Bank Transaction Table on Left Hand Side
Column A - Transaction references
Column B - Transaction amount
Column C - Formula to count the number of reference matches between the real transactions references in Column A and the forecast transactions reference range F3:F16
Column D - THIS IS THE PROBLEM I AM SEEKING A SOLUTION TO
Forecast Transactions on Right Hand Side
Column F - Forecast bank reference. (Either an exact match or a string contained within the string in Column A to allow for references that change every month i.e. Col A = "NETFLIX 23424589745897872134" and Col F = "NETFLIX")
Column G - Forecast transaction amount
The reason I am doing it with counting ref and price matches is that I then use these to automatically decide whether the transaction is a match to the forecast or not.
The problem is how to achieve my formula for Column D of my example spreadsheet. I need to check for price matches between each cell in column D and the range G3:G16 but only count matches where the transaction reference in column A matches to the range F3:F16 as per column C. This is to cut out many price matches that are not relevant.
The formula in C3 is currently
=if(A3="","",SUMPRODUCT(--ISNUMBER(SEARCH($F$3:$F$16,A3))*($F$3:$F$16<>"")))
This formula works great and is able to look at the range F3:F:16 and count both an exact match or strings contained within the string in Column A (i.e. Col A = "NETFLIX 23424589745897872134" and Col F = "NETFLIX"). This formula essentially allows me to count text strings in a range that exist within, or match, a single cell.
So at this point I cannot work out what the formula needs to be in Column D. I have tried to create a COUNTIFS formula with wildcards "" & & "" but I can't make anything work. My problem is that I can't utilise the current formula in Column C within a COUNTIFS in column D. Is there a way I can achieve the same outcome of Column C in a COUNTIF formula? Then I would be able to use that within a COUNTIFS formula in column D and my problem is solved... Hooray!
I know there must be a way but so far gogle has not been able to help me find the answer.
Please help!
Thank you :-)
in D3 try:
=INDEX(IFNA(VLOOKUP(REGEXEXTRACT(A3:A, TEXTJOIN("|", 1, F3:F)), F:G, 2, 0)))
update 1:
=INDEX(IF(A3:A="",,(B3:B=IFNA(VLOOKUP(REGEXEXTRACT(A3:A,
TEXTJOIN("|", 1, F3:F)), F:G, 2, 0)))*1))
update 2:
=INDEX(IF(A3:A="",,
IFNA(VLOOKUP(REGEXEXTRACT(A3:A, TEXTJOIN("|", 1, F3:F)), QUERY({F3:F},
"select Col1,count(Col1) group by Col1"), 2, ), 0)))

Why my ArrayFormula is giving error? How do I correct it? (I'm not looking for another Arrayformula as solutions!)

I wanted a ArrayFormula at C1 which gives the required result as shown.
Entry sheet:
(Column C is my required column)
Date Entered is the date when the Name is Assigned a group i.e. a, b, c, d, e, f
Criteria:
The value of count is purely on basis of Date Entered (if john is assigned a on lowest date(10-Jun) then count value is 1, if rose is assigned a on 2nd lowest date(17-Jun) then count value is 2).
The value of count does not change even when the data is sorted in any manner because Date Entered column values is always permanent & does not change.
New entry date could be any date not necessarily highest date (If a new entry with name Rydu is assigned a on 9-Jun then the it's count value will become 1, then john's (10-Jun) will become 2 and so on)
Example:
After I sort the data in any random order say like this:
Random ordered sheet:
(Count value remains permanent)
And when I do New entries in between (Row 4th & 14th) and after last row (Row 17th):
Random Ordered sheet:
(Doesn't matter where I do)
I already got a ArrayFormula which gives the required result:
={"AF Formula1"; ArrayFormula(IF(B2:B="", "", COUNTIFS(B$2:B, "="&B2:B, D$2:D, <"&D2:D)+1))}
I'm not looking for another Arrayformula as solutions. What I want is to know what is wrong in my ArrayFormula? and how do I correct it?
I tried to figure my own ArrayFormula but it's not working:
I got Formula for each cell:
=RANK($D2,FILTER($D$2:$D, $B$2:$B=$B2),1)
I figured out Filter doesn't work with ArrayFormula so I had to take a different approach.
I took help from my previous question answer (Arrayformula at H3) which was similar since in both cases each cell FILTER formula returns more than 1 value. (It was actually answered by player0)
Using the same technique I came up with this Formula which works absolutely fine :
=RANK($D2, ARRAYFORMULA(TRANSPOSE(SPLIT(VLOOKUP($B2, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ","))), 1)
Now when I tried converting it to ArrayFormula:
($D2 to $D2:$D & $B2 to $B2:$B)
=ARRAYFORMULA(RANK($D2:$D,TRANSPOSE(SPLIT(VLOOKUP($B2:$B, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ",")), 1))
It gives me an error "Did not find value '' in VLOOKUP evaluation", I figured out that the problem is only in VLOOKUP when I change $B2 to $B2:$B.
I'm sure VLOOKUP works with ArrayFormula, I fail to understand where my formula is going wrong! Please help me correct my ArrayFormula.
Here is the editable sheet link
if I understand correctly, you are trying to "rank" B column based on D column dates in such way that dates are in theoretical ascending order so if you randomize your dataset, the "rank" of each entry would stay same and not change based on the randomness you introduce.
therefore the correct formula would be:
={"fx"; INDEX(IFNA(VLOOKUP(B2:B&D2:D,
{INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1),
IFERROR(1/(1/COUNTIFS(
INDEX(SORT(B2:D, 3, 1),,1),
INDEX(SORT(B2:D, 3, 1),,1), ROW(B2:B), "<="&ROW(B2:B))))}, 2, 0)))}
{"fx"; ...} array of 2 tables (header & actual table) under each other eg. ;
outer shorter INDEX or longer ARRAYFORMULA (doesnt matter which one) is needed coz we are processing an array
IFNA for removing possible #N/A errors from VLOOKUP function when VLOOKUP fails to find a match
we VLOOKUP joint B and D column B2:B&D2:D in our virtual table {} and returning second 2 column if there is an exact match 0
our virtual table {INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1), ...} we VLOOKUP from is constructed with 2 columns next to each other eg. ,
we are getting the first column by creating an array of 2 columns {B2:B&D2:D, D2:D} next to each other where we SORT this array by date/2nd column 2, in ascending order 1 but all we need after sorting is the 1st column so we use INDEX where we bring all rows ,, and the first column 1
now lets take a look on how we getting the 2nd column of our virtual table by using COUNTIFS which will mimic the "rank"
IFERROR(1/(1/ is used to remove all zero values from the output (all empty rows would have 0 in it as the "rank")
under COUNTIFS we put 2 pairs of arguments: "if column is qual to column" and "if row is larger or equal to next row increment it by 1" ROW(B2:B), "<="&ROW(B2:B))
for "if column is qual to column" we do this twice and use range B2:D and sort it by date/3rd column 3 in ascending order 1 and of this we again need only the 1st column so we INDEX it and return all rows ,, and first column 1
with this formula you can add, remove or randomize your dataset and you will always get the right value for each of your rows
as for why your formula doesnt work... to not get #N/A error for vlookup you would need to define the end row of the range but still, the result wont be as you would expect coz formula is not the right one for this job.
as mentioned there are functions that are not supported under AF like SUM,AND,OR and then there are also functions which work but in a different way like IFS or with some limitations like SPLIT,GOOGLEFINANCE,etc.
I have answered you on the tab in your shared sheet called My Practice thusly:
You cannot split a two column array as you have attempted to do in cell CI2. That is why your formula does not work. You can only split a ONE column array.
I understand you are trying to learn, but attempting to use complicated formulas like that is going to make it harder I'm afraid.

How to get Date/ Time to work with Data Validation and INDEX(MATCH()) or VLOOKUP

I'm trying to set up a summary sheet that pulls relevant information based on input from three Data Validation drop-downs.
Link to the sheet: https://docs.google.com/spreadsheets/d/1LlOdONYI6hd2U5uVmD4C5i3WpuieOdohxIAnwfudUC8/edit?usp=sharing
I have a QUERY in 'Calculations'!E2, with Data Validation in 'Calculations'!F2 based on the results in 'Calculations'!E2, then two other QUERY in 'Calculations'!G2 and 'Calculations'!I2 with accompanying Data Validation in 'Calculations'!H2 and 'Calculations'!J2 respectively.
My first problem is when I get to the Data Validation in 'Calculations'!J2: Regardless of whether the selection looks identical to one of the times displayed in 'Calculations'!C:C, I always get an "Input must fall within the specified range" error.
My second problem: I can't get a formula to work that pulls the information I'm looking for from the "Form Responses" sheet. I've tried an INDEX(MATCH()) in 'Summary'!A8, and a VLOOKUP in 'Summary'!A10, but both say they can't find the date from 'Calculations'!J2.
I've tried adding/ removing significant digits with formatting and ROUND functions, but it won't match even though the data should be identical (the number in 'Calculations'!J2 is literally pulled directly from the dates in 'Form Responses'!A2:A, isn't it? Is that the problem?).
Thanks in advance for the help!
E2:
=UNIQUE(QUERY(A2:A, "where A is not null", 0))
G2:
=UNIQUE(QUERY(A2:C, "select B where A = '"&F2&"'", 0))
I2:
=ARRAYFORMULA(N(QUERY(A2:C, "select C where A = '"&F2&"' and B = '"&H2&"'", 0)))
K2:
=ARRAYFORMULA(IFNA(VLOOKUP(J2, {C2:C, A2:C}, {2, 3, 4}, 0)))

Google Sheets date query won't work on specific columns

I have data that I'm importing from Salesforce, and I'm using query functions to find all rows where any of the columns has a date in a given range. Here's an example of the data:
The query that's not working is:
=query('Salesforce Data'!A2:C,"SELECT A,C WHERE C >= date '"&TEXT(DATEVALUE($A$1),"yyyy-mm-dd")&"' AND C < date '"&TEXT(DATEVALUE($B$1),"yyyy-mm-dd")&"'")
I'm using the same query except in one case, it's looking at dates in column B, and in the other, it's looking at the dates in column C. The column B version works, the column C version does not. I have verified that there is at least one date in column C that falls in the range, so it should not be an issue of no data, as the error suggests:
I've looked over data formatting, and there is no difference between columns B and C in that regard. These are the same types of field in Salesforce as well, so I would not expect a difference in formatting. I tried manually changing the first value in column C to a date (that was an obvious difference between the columns), but that also didn't work.
After a lot of trial and error, I found the issue: it seems that Google Sheets classifies the column of data based on what the majority of the cells are. So, even though both columns B & C have some cells with valid dates and some with a - signifying null, column B has more dates than strings, but C has more strings than dates, so date compare queries won't work on column C at all.
My solution for now is to add a formula sheet to transform all of the null values, -, into a date that won't mess with my query, 1/1/1970:
Example formula:
=IF( OR('Salesforce Data'!C2="-",'Salesforce Data'!C2=""), date(1970,1,1), 'Salesforce Data'!C2)
Another solution would be to edit the data source, but this solution will work entirely within sheets.
Also note, I dragged this formula down far below where I needed, just in case, make sure that if you have a text column (like my column A), you replace empty values there with junk text of some sort. At first I replaced with 0 and then my text column wasn't picked up by the query.
try:
=ARRAYFORMULA(QUERY(TO_TEXT('Salesforce Data'!A2:C),
"select Col1,Col3
where Col3 >= date '"&TEXT(A1, "yyyy-mm-dd")&"'
and Col3 < date '"&TEXT(B1, "yyyy-mm-dd")&"'", 0))
Thank you thank you so so much. This thread helped me a lot.
I have used these from this thread. Someone may need in future:
"select A, B, C, G, H, J where I='"&TEXT($A$2, "dd-mmm-yyyy")&"'"
"select B, C WHERE F= date '"&TEXT(DATEVALUE($A$2),"yyyy-mm-dd")&"'"
"select A, B, C, G, H, J where I='"&TEXT($A$2, "dd-mmm-yyyy")&"' or I='"&TEXT($A$2, "d-mmm-yyyy")&"'"

Use vlookup to get exact match while is_sorted is TRUE

Is it possible to use Google Sheets VLOOKUP to get an exact match while using the sorted==TRUE option ?
Prefer to use VLOOKUP because I'm return multiple columns.
Would like to use the sort option because the data range is very large
(20,000 rows)
I didn't find any option in while reading the docs. Asking in case, there is an option I may have missed.
EDIT; I also checked the MATCH function, but the sort option is identical to VLOOKUP - so same situation.
EDIT; an ArrayFormula spreadsheet for users to reference
EDIT; full formula for my purposes for reference using Answer (double VLOOKUP) - very fast for even 20,000 rows
ARRAYFORMULA(IF(VLOOKUP(B:B,SORT(UNIQUE(B:B)),1,TRUE)=B:B,VLOOKUP(B:B,QUERY(A:B,"select B, count(A) group by B order by B label count(A) ''"),2,TRUE),0))
The double vlookup approach is to search for the primary key itself first, and only if it's found, proceed to retrieving the values from other columns.
If A:B is already sorted by A, and the value we look for is 42, then the formula is:
=if(vlookup(42, A:B, 1, true) = 42, vlookup(42, A:B, 2, true), na())
where the first vlookup checks if 42 is in column A, and only then passes the job to the second.
If A:B is not sorted, it can be sorted on the fly as in
=if(vlookup(42, sort(A:B), 1, true) = 42, vlookup(42, sort(A:B), 2, true), na())

Resources