Goal: Get the content of a cell in sheet 2 (column E) by searching for a keyword from sheet 1 in sheet 2.
To get the content I just need the relative position (row number) of the right cell in sheet 2 by looking for the unique keyword (sheet 1 column A) in sheet 2 column B.
sheet 1 column A (keywords):
1234567
7453773
9876543
Challenge: the cells in column B in sheet 2 includes not just one keyword (id) but several.
sheet 2 column B:
1234567 7453773 9876543
If there is just one keyword per cell the following formula works fine:
=index('sheet 2'!$E$2:$E,match(a2,'sheet 2'!$B$2:$B,0),1)
How can I find the relative row number if the cells include more keywords, separated by spaces?
try:
=ARRAYFORMULA(IFNA(IFNA(
VLOOKUP(A4:A7, Source!A2:B5, 2, 0),
VLOOKUP("*"&A4:A7&"*", Source!A2:B5, 2, 0))))
Related
I have a table with three Columns:
Column A: name of Item,
Column B: Lowest value of series,
Column C: the Highest value of series.
enter image description here
What I want to achieve is:
Generate series of item sequence from lowest number to highest number per row
So Apple 7 9 will yield: "Apple_7", "Apple_8", "Apple_9"
Concatenate/Join such sequence per row into Column D
So
Item
From
Until
Result
Apple
7
9
"Apple_7, Apple_8, Apple_9"
Berry
3
8
"Berry_3, Berry_4, Berry_5, Berry_6, Berry_7, Berry_8"
Doing it all using one Arrayformula, so that new row added can be automatically calculated.
Here is example sheet: https://docs.google.com/spreadsheets/d/1R5raKmmt5-aOIorAZGHjv_-fdySKWjCMB_FRQwm1vag/edit#gid=0
I tried in Column D:
arrayformula(textjoin(", ",true,arrayformula(A3:A&"_"&sequence(1,C3:C-B3:B+1,B3:B,1))))
Apparently, the sequence function only take value from Column B and join it in first row.
Any help will be appreciated.
Try below BYROW() formula (see your file, harun24hr sheet).
=BYROW(A3:INDEX(A3:A,COUNTA(A3:A)),LAMBDA(x,TEXTJOIN(";",1,INDEX(x&"_"& SEQUENCE(INDEX(C:C,ROW(x))-INDEX(B:B,ROW(x))+1,1,INDEX(B:B,ROW(x)))))))
Here A3:INDEX(A3:A,COUNTA(A3:A)) will return a array of values as well cell reference from A3 to last non empty cell in column A (Assume you do not have any blank rows inside data). If you have blank row, then you have to use different approach. See this post by #TheMaster
Then LAMBDA() will apply TEXTJOIN() and SEQUENCE() function for each cell of B as well as C column.
SEQUENCE() will make series from start to end number and by concatenating A column and will generate your desired strings.
Finally TEXTJOIN() will join all those strings with delimiter to a single cell.
try REDUCE:
=INDEX(QUERY(REDUCE(, A3:INDEX(A:A, MAX(ROW(A:A)*(A:A<>""))),
LAMBDA(x, a, {x; JOIN(, LAMBDA(i, f, u, i&"_"&SEQUENCE(1, u-f+1, f)&";")
(a, OFFSET(a,,1), OFFSET(a,,2)))})), "offset 1", ))
Column A is named "Quantity", which works in a simple formula:
I'm getting an error when attempting to use a named range in ISBETWEEN formula:
I verified that ISBETWEEN works when I use cell reference A2 instead of named range Quantity:
Any thoughts how I can fix? 😤
Your named range Quantity has its range set to A1:A but you are entering it in row 2, so error says there is no room in A2:A for A1:A unless you add a row but when you do it's the same coz you can't fit 3 keys into 2 keyholes (from one side each of course)
As seen on this sample:
See my comment to your original post.
Assuming that your named range Quantity is applied to the entire range A:A (and not A2:A), delete everything from Col B (including the header) and then place the following formula in cell B1:
=ArrayFormula( {"Test"; IF(A2:A="",, ISBETWEEN( FILTER(Quantity, ROW(Quantity)>1), 1, 5) ) } )
This one formula will create the header text (which you can change within the formula if you like) and all results for all valid, non-null rows.
FILTER(Quantity, ROW(Quantity)>1) is necessary to limit the full range of the named range Quantity to only those elements whose row is greater than (row) 1; this is because your results begin in Row 2.
You only need this one formula. As you add more data into Col A, the formula will process it.
I have went through some trial and error working on the wrong formulas for what I thought I needed and I've now narrowed it down to the exact formula/concept that I need for my use case.
I need a formula that searches the header row (Row 1 of Sheet 1) for occurrences of a specific string, for instance HouseNumber, and when it finds an occurrence, it grabs the data from the cell below it (from Row 2 of Sheet 1) and copies that over to a different sheet (starting at Row 2 of Sheet 2, leaving Row 1 as a header row), then continues looking for the second occurrence, then once it's found, it grabs the data from the cell below it (from Row 2 of Sheet 1), and copies that to the next row down on the different sheet (Row 3 of Sheet 2), then continues until no more occurrences are found, etc...
So for example, in Sheet 1 below, search Row 1 for all occurrences of HouseNumber and copy the values in the cells below them, from Row 2, over to separate rows in Sheet 2 (so a formula should go in Sheet 2 at A2).
Sheet 1:
HouseNumber.1
HouseStreet.1
HouseNumber.2
HouseStreet.2
123
1st Ave
456
2nd Ave
Sheet 2:
HN
123
456
Then do the same as above, except search for occurrences of HouseStreet (so a separate formula should go in Sheet 2 at B2).
Sheet 2:
HN
HS
123
1st Ave
456
2nd Ave
I have been trying nested functions with INDEX and MATCH, but it is not fully working and also it is only structured to search for / return one occurrence / value, not all occurrences/values.
If you have Windows Excel 2021+ (which have the functions used), you can use the following formulas:
For the address table 1, I used a Table with structured addressing, but you could use regular addressing if you prefer
HN: =FILTERXML("<t><s>" & TEXTJOIN("</s><s>",TRUE,FILTER(adrTbl,ISNUMBER(FIND("Number",adrTbl[#Headers])))) & "</s></t>","//s")
HS: =FILTERXML("<t><s>" & TEXTJOIN("</s><s>",TRUE,FILTER(adrTbl,ISNUMBER(FIND("Street",adrTbl[#Headers])))) & "</s></t>","//s")
results should spill down as far as needed
adrTbl
Results
Note that you can expand the table rows and/or columns and the formula should still work.
If you have an earlier version of Excel, I'd suggest using Power Query
Custom Function
Pivot with no aggregation
//credit: Cam Wallace https://www.dingbatdata.com/2018/03/08/non-aggregate-pivot-with-multiple-rows-in-powerquery/
//rename this query fnPivotAll
(Source as table,
ColToPivot as text,
ColForValues as text)=>
let
PivotColNames = List.Buffer(List.Distinct(Table.Column(Source,ColToPivot))),
#"Pivoted Column" = Table.Pivot(Source, PivotColNames, ColToPivot, ColForValues, each _),
TableFromRecordOfLists = (rec as record, fieldnames as list) =>
let
PartialRecord = Record.SelectFields(rec,fieldnames),
RecordToList = Record.ToList(PartialRecord),
Table = Table.FromColumns(RecordToList,fieldnames)
in
Table,
#"Added Custom" = Table.AddColumn(#"Pivoted Column", "Values", each TableFromRecordOfLists(_,PivotColNames)),
#"Removed Other Columns" = Table.RemoveColumns(#"Added Custom",PivotColNames),
#"Expanded Values" = Table.ExpandTableColumn(#"Removed Other Columns", "Values", PivotColNames)
in
#"Expanded Values"
Main Query
let
Source = Excel.CurrentWorkbook(){[Name="adrTbl"]}[Content],
//Unpivot all the columns to => data in just two columns
unPivot = Table.UnpivotOtherColumns(Source,{},"Attribute","Value"),
//split off the number from the column header to normalize them
//If you have other columns => unwanted attributes, may need to filter after the Split
#"Split Column by Delimiter" = Table.SplitColumn(unPivot, "Attribute", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
#"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Attribute.2"}),
//Pivot on the Attribute with no aggregation
pivot=fnPivotAll(#"Removed Columns","Attribute.1","Value")
in
pivot
Solved it with a formula:
=arrayformula(query(transpose(to_text(Sheet1!1:2)),"Select Col2 where Col1 contains 'HouseNumber'"))
Google Spreadsheets, match/lookup in ALL rows, except the current one
I have never come across a method that looks in all rows, except the current.
Say you have a match or vlookup and it looks in ALL the rows except the current one the formula is in.
We use a formula like below that verifies if a certain value already exists (using a MAX), but if it finds itself then the match or vlookup is always 1 (or in error)
A B
1 Formula: Does value 1 from cell A1 exist in column A?
2 Formula: Does value 1 from cell A2 exist in column A?
3 Formula: Does value 1 from cell A3 exist in column A?
4 Formula: Does value 1 from cell A4 exist in column A? Check all except row 4
Something like this
Formula in cell C4: match(A4;A$1:A3&A5:A)
Or Formula in cell C4: match(A4;A:A&[^A4])
You can use this formula from the second row of data onward (B2=):
=IFERROR(MATCH(A2,A$1:A1,0),MATCH(A2,A3:A,0)+ROWS(A$1:A1)+1)
If there is no match above the current cell it will search for a match below, and will return the correct index in the full column range by adding ROWS(A$1:A1)+1 to the below match result.
Copy this formula downward from B2 to B3 and so on.
If you are trying to check whether the value appears in the column except for the current row just use COUNTIF()
Put this formula in B2
=ARRAYFORMULA(IF($A$2:$A="",,IF(COUNTIF($A2:$A,"="&$A2:A)>1,True,False)))
Otherwise please specify what kind of output you want
Sheet 1
There are items in columns A - F. How do I use VLOOKUP to find a row and copy it to Sheet 2 when it matches criteria in column F?
This is the formula in a cell on Sheet 2: =VLOOKUP(apple,Sheet1!A:F, 2, FALSE)
When using VLOOKUP() the lookupvalue must be found in the first column of the lookuprange. If that is not the case, you can either use a combination of INDEX() and MATCH()
=INDEX(Sheet1!A:F, match("apple", Sheet1!F:F, 0))
or 'virtually' rearrange the layout of the table (on Sheet 1) so that the column where the match is to be expected (e.g. column F), is the first column.
=ArrayFormula(VLOOKUP("apple", {Sheet1!F:F, Sheet1!A:F}, {2,3,4,5,6,7}, 0))