Matching Columns From Different sheets - google-sheets

There are many similar questions on here but I can not find the answer I am after.
I am working in Google Sheets and need to write a conditional formatting equation that will highlight the B:C columns if they match an entry on the second sheet in the B:C columns. I do not know any search criteria past that which is where I keep running into an error. All the other questions here know what they are searching for. My work is fluid and new entries come in that may match an old one and I need to know that!
I use this formula on the first sheet to match entries specifically on the first sheet,
=COUNTIF(ARRAYFORMULA($B$3:$B$389&$C$3:$C$389),$B2&$C2)>1
This formula works great. If Lexington, SC is in row 2 and Lexington, SC is added again later in row 100, BAM they both light up red. Love that. The second equation I need is not so simple.
my data is:
SHEET 1 - Column B and Column C
County
State
Lexington
SC
Douglas
KS
Chase
KS
Clay
OH
Greenwood
NY
SHEET 2 - Column B and Column C
County
State
Saratoga
NY
Douglas
KS
Chase
KS
Clay
OH
Greenwood
SC
In this example above, I need the new formula to highlight Douglas KS, Chase KS, Clay OH on sheet one, because these three counties exists on Sheet Two.
I have tried MATCH, INDEX, VLOOKUP, etc. I keep running into an issue when I want TWO columns to be compared to TWO columns. It needs to be county name AND state.
Thank you to the community for any help you can give. I will provide more information if it is needed! I think this sums up my issue though.
QUERY ATTEMPTS
=COUNTIF(ARRAYFORMULA($B$2:$B$20&$C$2:$C$20),$B2&$C2)>1
=COUNTIF(ARRAYFORMULA('Sheet 2'!$B$2:$B$20&$C$2:$C$20),$B2&$C2)>1
=COUNTIF(ARRAYFORMULA(indirect("Sheet1!$B$2:$B$C$2:$C"),indirect("Sheet2!$B2:$B&$C2:$C")))>1
=ARRAYFORMULA(IFERROR(VLOOKUP(B2:C,"Sheet 2!$B2:$C",2, FALSE),""))
=ARRAYFORMULA(INDEX(B2:B19, MATCH(1, FIND(E2, C2:C19)), 0))
=ARRAYFORMULA(INDEX(B2:C,MATCH(indirect("Sheet 2!$B2:$C"),0)))
=MATCH($B2&$C2,indirect('Sheet 2'!$B2:$B&'Sheet 2'!$C2:$C"),0)
=MATCH($B2,indirect("Sheet 2!$B2:$C"),0)
=MATCH("Sheet 1!$B2&$C2",indirect("Sheet 2!$B2:$C"),0)
=MATCH("Sheet 1!$B:$C"),indirect("Sheet 2!$B:$C"),0)
=MATCH((B2&C2),indirect("Sheet 2!(B2&C2)"),0)
=INDEX($B2:$C2,MATCH($B2&$C2,indirect("Sheet 2!$B2:$C"),0)
=INDEX(B:C,MATCH($B2&$C2,indirect("Sheet 2!$B2:$C"),0)
=INDEX(B2:C710,MATCH(0,(B:C="Sheet 2!$B:$C"),0))
The only query I have gotten to work only works on the B column
=match($B2,indirect("Ready to Start!$B2:$B"),0)

in conditional formatting (and data validation) whenever you want to refer to another sheet, that sheet's range needs to be INDIRECTed. if you got a joint range (like you do) both of them need to be wrapped in INDIRECT
try:
=COUNTIF(ARRAYFORMULA($B$3:$B$389&$C$3:$C$389),
INDIRECT("Sheet 2!B2")&INDIRECT("Sheet 2!C2"))>1
or:
=COUNTIF(ARRAYFORMULA(INDIRECT("Sheet 2!B3:B389")&INDIRECT("Sheet 2!C3:C389")),
$B2&$C2)>1
but note that this will work only if let's say B4&C4 on BOTH sheets are the same.
if one sheet compared to other has different sorting of the same values you will need a completely different formula...
if your sheets are named exactly:
Sheet 1
Sheet 2
try this in Sheet 1:
=($A2<>"")*REGEXMATCH($A2&$B2, TEXTJOIN("|", 1,
INDIRECT("Sheet 2!A2:A")&INDIRECT("Sheet 2!B2:B")))

Related

Stack multiple queried Importranges with a single word between the two sets of imported data?

I have a master sheet that contains all of the data for other sheets. Column A in the master sheet is the name for who's sheet it will import to. So if the name is "John" then every row that has "John" in column A from the master sheet will be imported into John's sheet. I have the person's name in cell G1 of their own respective sheet and use the following formula.
=ARRAYFORMULA(IFNA(QUERY(IMPORTRANGE("LINK_TO_SHEET","Assignments!A2:Q"),"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1='"&G1&"'",0),""))
Master sheet looks like this:
Assigned To
Name
State
City
John
Blake G.
Arizona
Phoenix
Andy
Chase C.
Arizona
Phoenix
John
Amy B.
New Mexico
Santa Fe
John
Bill S.
Texas
Austin
John's sheet will look like this:
Name
State
City
Blake G.
Arizona
Phoenix
Amy B.
New Mexico
Santa Fe
Bill
Texas
Austin
I want to separate the data based on what is in Col17 and put a single word between the two data sets. Col17 has either a Y or a N so I can just add AND Col17='N' to the existing formula. I double up the formula, but changed the last condition to be Col17='Y' so that I can pull the two data sets separately and on top of each other.
={ARRAYFORMULA(IFNA(QUERY(IMPORTRANGE("LINK_TO_SHEET","Assignments!A2:Q"),"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1='"&G1&"' AND Col17='N'",0),""));ARRAYFORMULA(IFNA(QUERY(IMPORTRANGE("LINK_TO_SHEET","Assignments!A2:Q"),"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1='"&G1&"' AND Col17='Y'",0),""))}
What I want to do is add a single word between the two imported sets of data. It should like kinda like this:
Name
State
City
Blake G.
Arizona
Phoenix
Amy B.
New Mexico
Santa Fe
Inactive
Bill
Texas
Austin
I added the word inactive so the middle looks like ""));"Inactive";ARRAY between the two formulas but because of how Query works I get an error saying the array lengths for each formula do not match. Is there alternative to help make this happen or will I need to figure out a workaround with something that isn't Query?
SUGGESTION
Feel free to comment below if ever your question has been misunderstood.
In my understanding, here's your process:
The first formula will list all data that has N value in Col17 .
The second formula will list all data that has Y value in Col17.
This second formula should also have an Inactive title header.
Merge the two formulas separated by the word "Inactive".
If I got it correctly, you could use the label clause to add "Inactive" in your second Query function as seen on this tweaked formula:
={ARRAYFORMULA(IFNA(QUERY(IMPORTRANGE("SHEET_URL","A1:Q"),"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1 = '"&G1&"' AND Col17 = 'Y'"),0));ARRAYFORMULA(IFNA(QUERY(IMPORTRANGE("SHEET_URL","A1:Q"),"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1 = '"&G1&"' AND Col17 = 'N' label Col2 'Inactive'"),0))}
Demo
Sample result.
E.g. If there's new data added that should be under "Inactive".
Main Sheet
John's Sheet
#SputnikDrunk2 is a very good workaround. Just in case you decide to stack different types of ranges that are not queries, you should consider that they need to have the same amount of columns. So if you add a new row it should have the 12 columns you have from your Queries. One way would be like this:
={ARRAYFORMULA(IFNA(QUERY(IMPORTRANGE("LINK_TO_SHEET","Assignments!A2:Q"),"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1='"&G1&"' AND Col17='N'",0),""));
{"Inactive","","","","","","","","","","",""};
ARRAYFORMULA(IFNA(QUERY(IMPORTRANGE("LINK_TO_SHEET","Assignments!A2:Q"),"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1='"&G1&"' AND Col17='Y'",0),""))}
Another option to avoid creating so many "","","","" is to use this "trick" that divides a range by 0, and with IFERROR it returns empty cells:
{"Inactive",INDEX (IFERROR(SEQUENCE(1,11)/0,))};
Here's another approach:
=lambda(z,
{filter(choosecols(z,2,3,4,5,6,7,8,9,10,11,12,13),index(z,,1)=A1,index(z,,17)="N");
{"Inactive",makearray(1,11,lambda(r,c,iferror(1/0)))};
filter(choosecols(z,2,3,4,5,6,7,8,9,10,11,12,13),index(z,,1)=A1,index(z,,17)="Y")}
)(A1:Q4)
A1:Q4 part in the formula should be replaced with your importrange Fx
2,3,4,5,6,7,8,9,10,11,12,13 part can also be replaced with shorter sequence(1,12,2,1)

Lookup Acct. Balance on specified day in Google Sheets

Sounded so simple! I have a sheet called "Account", containing a running balance in column "G" and I have another sheet called "Performance", with a table which lists historical dates and column "D" needs to lookup the account balance on the day stated in column "A".
"Account" Sheet
"Performance" Sheet
For example, Performance!D2 should be "210,000.00".
Performance!D7 should be "110,000.00".
Performance!D9 would be "40,000.00".
To make this slightly more difficult I like to put formulas into the heading row as arrayformulas where possible, to avoid problems when copying and pasting data or adding new rows, etc.
I've tried many different possibilities and nothing has worked. I'm currently trying to make the following formula work, which is in Performance!D1.
=ARRAYFORMULA(if(row(D1:D) = 1, "Cash", VLOOKUP(A1:A, MIN('Balance'!A4:A <= A1:A), 7, 1)))
I've also tried some solutions involving MATCH(), FILTER(), VLOOKUP() and LOOKUP() but so far no cookie!
this should work:
=ARRAYFORMULA({"Cash";if(A2:A="",,VLOOKUP(A2:A, SORT('Account'!A4:G),7,TRUE))})
VLOOKUP(...,true) returns the value associated with the closest match in the first column without going over. Provided that the range into which you're doing the vlookup is sorted by the first column of that range.

Filter function in Google Sheet - multiple columns

I have a table with names of performers and the activities they performed in which cities. Now, I am trying to find out who all performed in which city using filter formula - Check C15 in below sheet.
https://docs.google.com/spreadsheets/d/19U0vjtABXQ-MltxZoW7v0vjt1L6gM2Lc2VP3Z-BuKwE/edit?usp=sharing
The formula I am trying to use is:
=join(", ",transpose(iferror(filter(A2:A11,REGEXMATCH(C2:G11,"Chicago")))))
If I change G11 to C11 in above formula, I can see some output which is incorrect.
(a) I want the names of performers who performed in Chicago from columns C all the way to G.
(b) Even if I keep it as C11, it gives the name of only the first performer.. and not all those who performed in Chicago in column C
For just Chicago, the output should be:
Nils, Tom in F15
Nils, Tom, Jack, Amanda, Sam in C15
Any help will be greatly appreciated.
=join(", ",transpose(iferror(filter(A2:A11,REGEXMATCH(B2:B11,"Chicago")))))
works for me and I get Nils,Tom in F15.
One way of getting the matches in all columns is to get the row totals like this, and where they aren't zero to join the values in the first column:
=ArrayFormula(textjoin(",",true,if(mmult(n(regexmatch(B$2:G$11,A15)),transpose(column(B:G))),A$2:A$11,)))
You could use something like this:
=join(", ",transpose(filter(A2:A11,REGEXMATCH(C2:C11&D2:D11&E2:E11&F2:F11&G2:G11,"Chicago"))))

How can I make an statement to output different things based on other cells

I'm writing a spreadsheet for a planning of some sort. It is about a band with multiple musicians on sometimes the same instruments. I've made two sheets. One for the musicians to let them show when they'll be present, while the other has to make an overview of all musicians present on certain dates.
I've already made an if statement to show when one of them is present, which would look like this in simple code:
if(B2)
print("Eric")
What I actually would want is an if statement to show when they are both present. In simple code it would look like this:
if(B2)
print("Eric")
if(B2 && C2)
print(", ")
if(C2)
print("Frank")
Really simplified.
I've made an example spreadsheet to show what I've already got. Here it is:
https://docs.google.com/spreadsheets/d/17gyoh5NUdiUWB_Nq0w3FAc1OsWQygzRYd_kzm0ijdJA/edit?usp=sharing
So what I would like to see with input as: B3=TRUE, C3=TRUE.
in sheet2 it should then show in B3: Eric, Frank
How about this answer? I think that there are several answers for your situation. So please think of this as one of them.
Sample formulas:
Please put 1st and 2nd formula to "B3" and "C3" of Sheet2, respectively.
=TEXTJOIN(", "; TRUE; ARRAYFORMULA(IF(Sheet1!B3:C3=TRUE; Sheet1!$B$2:$C$2;)))
and
=TEXTJOIN(", "; TRUE; ARRAYFORMULA(IF(Sheet1!D3:G3=TRUE; Sheet1!$D$2:$G$2;)))
Retrieve values that the checkbox is checked using IF and ARRAYFORMULA().
Join the retrieved values using TEXTJOIN().
Result:
For example, when B3, C3, E3 and F3 of Sheet1 are checked, Sheet2 becomes as follows.
References:
ARRAYFORMULA
TEXTJOIN
If I misunderstand your question, I'm sorry.

Is there a function that can create an expanding array formula that conditionally sums a column based on multiple criteria?

To start, this is my first time posting and so please let me know if I can fix my post in any way to make it easier to answer.
I am trying to create an auto-expanding array formula
I have a sheet with my investment asset mix that including amounts of shares owned of each particular stock, and a sheet that tracks when I receive dividends. My goal is to write an automatically expanding array formula that will sum up the amount of shares that own of a stock on the date a dividend is received and return that value. I have written three different formulas that all accomplish this but none of them will auto-expand as an array.
I'm sure there are a lot of solutions I've overlooked. To boil it down, I need an expanding array formula that will sum the "Shares" column of my asset mix sheet ('Asset Mix'!D2:D, or 'AssetMixShares') conditionally. The name of the stock entered in 'Dividends'!C2:C needs to match the name of the stock in 'Asset Mix'!A2:A (or the named range 'AssetMixStocks'). It then needs to check the dates in 'Asset Mix'!C2:C (or 'AssetMixDates') against the dates in 'Dividends'!A2:A and sum all share amounts where the purchase date is less than (earlier than) the Ex-Dividend Date.
I could probably write some sort of vlookup array on the "Running Total" column -- 'Asset Mix'!E:E -- that would solve the issue, but I'm hoping to eliminate that column. I feel very strongly that what I'm trying to do should be possible without the help of a running total column -- I just don't have the knowledge.
I have tried countless functions and formulas, but the four that I currently have in my example worksheet are SUM, SUMPRODUCT, DSUM, and QUERY.
Attempt 1
SUM and IF
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Attempt 2
SUMPRODUCT
=({arrayformula(SUMPRODUCT(--((AssetMixStock=(indirect("C"&ROW())))*(AssetMixDate<(indirect("A"&ROW())))),AssetMixShares))})
Attempt 3
DSUM
=DSUM('Asset Mix'!A:E,"Shares",{"Date","Stock";"<"&A2,C2})
Attempt 4
QUERY
=arrayformula(query(AssetMix,"Select sum(D) where A = '"&C2:C&"' and C < date'"&(text(year(A2:A),"0000") & "-" & text(month(A2:A),"00") & "-" & text(day(A2:A),"00"))&"' label sum(D) ''",0))
These will all work, as long as I manually drag the formula down, but I want to write some sort of formula that will auto-expand to the bottom of the Dividends sheet.
I have tried to create a Dummy sheet that has both of the relevant sheets. Please let me know if you can access it -- the link is below.
https://docs.google.com/spreadsheets/d/1wlKffma0NJ0KrlWxyX_N20y62azsGpFp3enhmjzJK1Q/edit?usp=sharing
Thanks so much for getting this far and any help you can provide!
We can focus in the first formula to understand a way to make it "self-expandable". As we see it contains references to the cells A2 and C2 in "Dividends" sheet:
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Every time some data appears in these columns (A and C), the formula should work. We can control the presence of the formula by onEdit trigger, if editing is manual. Consider the code:
function onEdit(e) {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
if (sheet.getName() == 'Dividends') {
var row = e.range.getRow();
for (var offset = 0; offset < e.range.getHeight(); offset++) {
sheet.getRange(3, 10).copyTo(sheet.getRange(row + offset, 10));
}
}
}
It checks any modification on the sheet "Dividends" and copies required formula to the modified row(s). This way the formula is expanded for other rows in use.
Well, it's solved! I'll leave this up in case anyone else has the same question.
A kind soul explained the magic of MMULT() to me, and wrote this solution.
=ARRAYFORMULA(MMULT((C2:C=TRANSPOSE('Asset Mix'!A2:A))*(A2:A>TRANSPOSE('Asset Mix'!C2:C)),N('Asset Mix'!D2:D))

Resources