I have a long, long query function into a if function from three cells (below is a simple version with two cells):
=IF(B2="All";Query(Sheet!1:100000;"select B,C,F"); Query(Sheet!1:100000;"select B,C,F where C contains """&B2&""" and B contains """&D2&""" ")
B2 and D2 are the cells where I have item lists that fill my query
Now I want: insert a blank value at the start of the query. I can use:
if (isblank(B2);iferror(1/0)
but doesn't go with two or more cells.
=if (isblank(B2);iferror(1/0), if(isblank(D2);iferror(1/0),,IF(B2="All";Query(Sheet1!1:100000;"select B,C,F"); Query(Sheet1!1:100000;"select B,C,F, where C contains """&B2&""" and B contains """&D2&""" "))))
More, I want learn to use different conditions (with OR and AND).
Can you help me?
I don't know what you want either but guess it might be:
=IF(or(ISBLANK(B2),isblank(D2)),iferror(1/0),if(B2="All",Query(Sheet4!1:100000,"select B,C,F"), Query(Sheet4!1:100000,"select B,C,F where C contains """&B2&""" and B contains """&D2&""" ",C9)))
Related
I want to do some function like sql joint table.
But I really dont know if google sheet can do it.
I want to compare two columns and return the cost, how can I perform it?
ColA ColB ColG ColH
Type Cost Type Cost
A 100 B
B 200 E
C 300 D
D 400 A
E 500 C
I want colH would show colB data when comparing colG to colA,
is there any function in google sheet that can do it?
It's just like the joint table function sql table.
Thanks
Vertical Lookup function VLOOKUP is what you want to solve this problem.
VLOOKUP(search_key, range, index, [is_sorted])
Pass the following parameters:
search_key is the value to search in the costs array, column G in you case.
range is the costs array
index is the column to return in the costs array, the second one
is_sorted should be set to TRUE, as you do not want incorrect costs to be returned, if the value in column G does not exist in the costs array.
Hence, the formula to use in H2 is:
=VLOOKUP(G2,A1:B6,2,false)
Then, in order to allow you to use the same formula in all cells inside the column H, you need you make sure that it is always A1:B6 which is looked up as the costs array. If you copy paste the formula above from H2 to H3, it will adapt it and move the array one line below (A2:B7), which is not what you want. To solve this, you should use the dollar sign to lock the costs array range. This article explains how it works.
The formula then becomes the one below, and you can copy/paste it inside the whole column H:
=VLOOKUP(G2,$A$1:$B$6,2,false)
Demo sheet with the solution in place: https://docs.google.com/spreadsheets/d/1rzvCmgTi1DgA5Dbwb_iwKYc5RW_9uwFs2sVR0PbN7Ic/edit?usp=sharing
I have three columns of data (columns A, B, and C).
Column A contains a number
Column B contains a name
Column C contains a URL
In cell E1, I have a drop down list that references the cells in column A.
I need a function that generates a hyperlink based on the number picked from the drop down menu using the cells that are adjacent in columns B and C. In otherwords, if E1 = any cell in column A, then create a hyperlink with the adjacent cells in columns B and C... more generally:
=IF(E1=[Any cell in column A],HYPERLINK([same row column C],[same row column B],"")
Is it possible to create a dynamic formula that will do this? I have found similar questions, but none that ask precisely this, and I cannot seem to piece together my searches to come up with a solution.
thanks to any who help.
enter image description here
I hope you looking for like this
formula:
=HYPERLINK(VLOOKUP(E1;A1:C5;3;0);VLOOKUP(E1;A1:C5;3;0))
I believe (if i'm mentally imagining your spreadsheet right) that you'd be better off using the VLookup function to retrieve the URL. If i'm wrong and it's reversed, the HLookup function may be what you need. They're similar, just depending on the pivot of whether you're aiming for a value in a row (Vlookup) or Column (Hlookup).
This article does a pretty good job of explaining HLookup:
https://support.office.com/en-us/article/VLOOKUP-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1
You can then use the lookup value for the HYPERLINK function to set the display text and the URL.
I have a table in Excel 2013 that has has thousands of records of food items (Beef-frozen, beef-chilled, beef-brisket, beef-ribs, chicken-fillet, chicken-whole, fish-skinned, fish-whole, yogurt, lettuce-imported, lettuce-frozen, tomato-fresh,tomato, water, milk,...etc) stored in column A. Notice the value may contain other content than the food item name.
I created column B next to column A. I want column B to hold the category of the food item in column A. For example, if A1 has in it "Beef" or "Chicken" or "Fish" then B1 should equal "Meat". If A1 has in it "Tomato" or "Lettuce" or "Onion" then B1 should equal "Vegetable".
What is the best way to achieve it?
Assuming you have column headers, enter this formula in cell B2:
=REPT("Meat",MAX(IFERROR(MATCH({"*beef*","*chicken*","*fish*"},A2,),))) & REPT("Vegetable",MAX(IFERROR(MATCH({"*tomato*","*lettuce*","*onion*"},A2,),)))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.
Now copy B2 and select B3 down as far as you need and paste.
Note: please look closely at the big gap in the middle of the formula. You'll see that this is really two separate formulas concatenated together with an ampersand. You can easily extend this formula in the same way by adding another phrase similar to the first two for a new category. In fact, you could add many more categories in this fashion.
Set up a two column table. Name it, for example FoodTable. Have the first column Named Word (for keyword) and the second column Type, for the type of product. Something like this:
Then, with your data in column A, enter the following formula in B1 and fill down:
=LOOKUP(2,1/ISNUMBER(FIND(FoodTable[Word],A1)),FoodTable[Type])
Results:
Given
O 1 2 3 A
A 4 5 6 B
B 7 8 9 D
O 3
C 15
T 18
I'm looking for VBA code to validate that when column A contains a value that the remaining columns also contain values and when it doesn't contain a value, that columns 2 & 5 also contain values but 3 & 4 don't.
I've simplified the example, in a real sheet there will be many more columns and rows to check.
I've considered COUNTIF and INDEX/MATCH and array forumlas but from my understanding these all work on single columns at a time.
I want to do something like WHEN A1:An<>"" THEN COUNTBLANK(B:E) ELSE COUNTA (C:D)
Is the best way to use autofilter using blanks in A and then countblank and then a second autofilter for values in A.
Thanks
You can do it with a couple of nested IF formulae as follows:
=IF(A1<>"",
"A not empty, "&IF(COUNTBLANK(B1:E1)=0,
"B:E not blank",
"B:E have blanks"),
"A blank, "&IF(AND(COUNTBLANK(B1)+COUNTBLANK(E1)=0,
COUNTBLANK(C1)+COUNTBLANK(D1)=2),
"Columns 2&5 have values and Columns 3&4 don't",
"but condition not met"))
The reason for going down the VBA route is that I want a generic reusable function as opposed to a formula I copy between cells and sheets changing the columns etc along the way ending up with a lot of duplicate code.
So something that takes a column to test and a value to test it with. Third parameter would be a range of columns to validate, and the fourth parameter the validation.
I don't want any solution to have the columns hard coded and I don't want intermediate totals at the end of rows. This is fairly easily achieved in Excel itself...
The reason for trying to use countblank is that I can apply it to a range.
After a lot of searching I discovered this (the columns don't match the original example)
=SUMPRODUCT((A2:A19<>"")*(B2:D19=""))
=SUMPRODUCT((A2:A19="")*(D2:D19=""))
=SUMPRODUCT((A2:A19="")*(B2:C19<>""))
Nice huh? I just need to convert it into VBA now.
Thanks
This question is concerning joining two databases in Google spreadsheet using =QUERY function
I have a table like so in range A1:C3
a d g
b e h
c f i
I have another table
c j m
a k n
b l o
I want the final table to look like this
a d g k n
b e h l o
c f i j m
I can do this by using a vlookup function pretty easily in cell D1 and paste it down and across, but my dataset is huge. I would need a whole page of vlookups and Google Spreadsheet tells I'm at my limit in complexities.
I look at the Google's Query Language reference... there doesn't seem to be an type of "join" functions mentioned. You would think it would be an easy "join on A" type operation.
Can anybody solves this without a vlookup?
Short answer
Google QUERY Language version 0.7 (2016) doesn't include a JOIN (LEFT JOIN) operator but this could be achieved by using an array formula which result could be used as input for the QUERY function or for other uses.
Explanation
Array formulas and the array handling features of Google Sheets make possible to make a JOIN between two simple tables. In order to make easier to read, the proposed formula use named ranges instead of range references.
Named Ranges
table1 : Sheet1!A1:C3
table2 : Sheet2!A1:C3
ID : Sheet1!A1:A3
Formula
=ArrayFormula(
{
table1,
vlookup(ID,table2,COLUMN(Indirect("R1C2:R1C"&COLUMNS(table2),0)),0)
}
)
Remarks:
Using open ended ranges is possible but this could make the spreadsheet slower.
To speed up the recalculation time :
Replace Indirect("R1C2:R1C"&COLUMNS(table2),0) by an array of constants from 2 to number of columns of table2.
Remove the empty rows from the spreadsheet
Example
See this sheet for an example
Note
On 2017 Google improved the official help article in English about QUERY, QUERY function. It still doesn't include yet topics like this but could be helpful to understand how it works.
So, this answers how you do it WITH a Vlookup-function, but in only one cell.
In your example, given that each table of data has the following cell references:
Table1: Sheet1!A1:C3
a d g
b e h
c f i
Table2: Sheet2!A1:C3
c j m
a k n
b l o
This is how the formula should be constructed.
Join-formula
=ArrayFormula(
{
Sheet1!A1:C,
vlookup(Sheet1!A1:A, {Sheet2!A1:A, Sheet2!B1:C}, {2,3}, false)
}
)
The key to get this formula to work, is to understand how to use curly brackets in the Vlookup Range. You basically define the first cell reference of the Range as the column which is to be a match to the Vlookup Search_Key. The rest of the cell references in the Range is in relation to the columns which you would like to join.
The Index is written as {2,3} to return the second and third column of the Range (the Range consists of a total of 3 columns); curly brackets has nothing to do with Arrayformula in the Vlookup Index, but is necessary to return multiple columns from the Vlookup function. The reason to not write {1,2,3} is because you would not like to include the column which is being used for the purpose of joining.
Example where the column in table2 used for joining, is located in a different column (to the right of the data which is to be joined)
This kind of Join-formula can be utilized even if the join-column in the second table is located as the third column of that table.
Let's say that the raw-data in this example would look like this:
Table1 (Sheet1):
a d g
b e h
c f i
Table2 (Sheet2):
j m c
k n a
l o b
If you write the formula like this, you'll still get the desired outcome (as displayed in the table of joined data):
=ArrayFormula(
{
Sheet1!A1:C,
vlookup(Sheet1!A1:A, {Sheet2!C1:C, Sheet2!A1:B}, {2,3}, false)
}
)
The table of joined data:
a d g k n
b e h l o
c f i j m
In the Join-formula, notice that the third column of Table2 is located as the first cell reference in the Vlookup Range!
The reason to why this works, is because when you use curly brackets in the Range (in conjunction with Arrayformula), the Vlookup Search_Key will NOT look for a column as a common denominator within the raw-data, instead it will use the Array within curly brackets as a reference to find a column as a common denominator (by default this is the first column of the Range).
I've written a comprehensive guide about this topic called:
'Mastering Join-formulas in Google Sheets'
You can use ARRAYFORMULA or YOU can just drag this formula:
after an import or QUERY-ing the first table; in the D column:
=QUERY(Sheet2!A1:C3, "Select B,C WHERE A='" & A1 & "'", 0)
I solved this by using Javascript LINQ (language integrated query).
It lets you specify Javascript with complex join conditions. You can also perform other SQL queries such as Grouping, Projecting, Sorting and Filtering your sheets as if they were database tables. Look at the links below.
Note that in the LINQ query language I replaced all spaces in column names with underscores to make them valid JS identifiers.
https://docs.google.com/spreadsheets/d/1DHtQlQUlo-X_YVfo-Wo-b7315sSk2pxL5ci4Y9lxvZo/edit?usp=sharing
https://script.google.com/d/1R5L2ReHJrBRwyoSoVOFLzEQZiGtxidPfPkAeVownt7SWX6TpacY7gA7j/edit?usp=sharing
If you can map each "index" (a, b, c) to a specific row or column, then you could use the INDEX function.
In this case, you could probably map 'a' to column A (or row 1), 'b' to column B (or row 2), and so on.
Also, Merge Tables seem to address this exact use case.
With the 'other' table in A5:C7, please try:
=query({A1:C3,query(sort(A5:C7,1,TRUE),"Select Col2,Col3")})