how to get index of word from column containing array in all its cells - google-sheets

This is fake data for question purpose
sorry for using images rather than markdown table but it would have been very hard to explain if i used markdown table
This is my DATA named Work Sheet where Y and Z is always going to be array and both have corresponding value. EX: for row2:
WBC = 33
this is my stats Sheet where i need to get value of Parameter[x] based on Day & Disease
This is where i took B$151 to B166 and now need value of it from DATA!Z2:Z (Lab values) based on name of parameter,Disease , Day .
where selected cell (B169) has formula:
B166 = RBC
A169 = DAY 1
B1 = Gastroenteritis
=MODE(INDEX(SPLIT(query(DATA!$E$2:$Z, "Select Z where Y contains '"&B$166&"' and E contains '"&$A169&"' and X contains '"&B$1&"' limit 10"),",",1),0,B$167))
Now problem is in DATA sheet user can input item at any index. right now i am using fixed index B$167, but it will break entirely and give wrong results if user changes index of that term. is there any way where i can replace B$167 with dynamic like searching that parameter name in that E,X (Day, Disease). and get index of it and change B$167 with it
i have tried using match search index and pretty everything in my knowledge but problem was Match function only takes single cell and column, so i can't give entire DATA!Y2:Y and split them and then get index. but did not work.
this was the limit of solution i was able to reach.
where A5 = WBC or any in regards
given Y2 becuase was getting error on Y2:Y
=MODE(INDEX(SPLIT(FLATTEN(FILTER(DATA!Z2:Z,DATA!X2:X=B4, DATA!E2:E=C4)),","),0,MATCH(A5,SPLIT(FLATTEN(DATA!Y2),","),)))
but using this will only give index if it is in y2 and also there is no garranty
that parameter is going to be in same index in all cells all the time
i have tried to add 4th condition to Filter on above formula such as search, regexmatch and all but i was not able to solve.
CURRENT SOLUTION: EDIT2
[NEW SHEET][1]
[1]: https://i.stack.imgur.com/rNDh8.png
right now i have did kind of like this and it will be ok if i can combine those 2 (Disease, value) into single cell like this.
RBC: 11
WBC: 33
so i don't need to manually add disease name and Value column each time. i googled but found that i can't skip columns in formula output
so i moved to this.
EDIT2:
i solved this way, now everything is automatic.
where 1 = n
=INDEX(UNIQUE({A2:A}),1)

Related

How do I filter a large dataset in Google Sheets without getting duplicates returned?

I am trying to create a new worksheet in a Google Sheets doc where I need to filter a Master data set based on values in a specific column.
I originally did a VLOOKUP in each specific column that I wanted returned but it brough back blank rows for the corresponding rows that did not match, and eventually it broke for some reason and stopped returning the correct data.
I have been trying to find a new way to do it and have most recently been trying XLOOKUP, but it returns duplicate rows of each correct match.
The original datasheet is mostly populated itself by VLOOKUPS, drawing in information from other trackers so I feel this must be why it is falling over.
The dataset looks roughly like this:
ID
Y/N
Last Name
First Name
col
col1
col2
etc
1
Y
SMITH
A
Cell 1
Cell 2
Cell 1
Cell 2
2
N
JONES
B
Cell 1
Cell 2
Cell 1
Cell 2
There are 40+columns in the tracker but I basically want to have a new sheet where I filter and return only the 'Y' values in the Y/N column, and return columns A:N (including the ID column) without leaving blank rows between the matches, and without returning dupllicates.
I have tried everything I can think of but I just cannot make it work, so any help on the matter would be GREATLY appreciated.
Thanks for reading.
try:
=FILTER(Sheet1!A:N; Sheet1!B:B="Y")
You can also try along with player0 answer, if you want also to import the headers:
=Query(Sheet1!A:N,"Select * Where B = 'Y'"),TRUE)

How can I read the value of a cell directly into a cell reference?

In Google Spreadsheets, I want to read a cell containing the string 'e' into a formula which uses the 'e' as the horizontal component of a cell reference, eg 'e12'.
Hopefully clearer example:
a1 contains 'e'
a2 needs to contain 'e2'
then a2:a10 can contain 'eX' where X is 2 to 10.
I'm aware of the INDIRECT method, but I can't see how to use that to populate a2:a10 without a corresponding column of cells all containing 'e', one for each aX.
Perhaps I'm barking up the wrong tree.
I've got a table with list of names on the x axis and dates of meetings on the y axis. In each table element we have some string value to represent if they attended the meeting - eg "y" for attended the meeting "n" for did not, "a" for apologised for abscence in advance.
I also have a list, corresponding to the names on the x axis, of attendance, eg person1 has been to 60% of meetings. The trouble is that for every new meeting I insert a new column closest to the names list, and move all the other meetings one cell to the right. This means that for every new meeting, I have to update the formula with a new cell reference.
Before inserting a new meeting date, the formula looks roughly like DOSOMETHING(b2:y2). I then insert a column to the left of the b column. Google sheets cleverly updates the formula so to be DOSOMETHING(c2:z2), even though I really want the range to be b2:z2. I have tried DOSOMETHING($b2:y2), but inserting the column still causes this problem.
Thank you
instead of:
=DOSOMETHING(B2:Y2)
use this:
=DOSOMETHING(OFFSET($A2,0,1,1,99999))
the offset reference won't get messed up by the insertion of a column since it referrences column B by OFFSETing from column A. 99999 is just an arbitrarily large number that means "all the way to the right of the sheet.
you can read about offset here.
try like this in row 2:
=INDIRECT(A1&ROW()&":"&A1&10)

Google sheets lookup with the query function within an array

I have a following formula in my google sheets
=TEXTJOIN(" -- ",TRUE,QUERY('sheetName'!B2:F,"SELECT F WHERE B = '"&$A3&"'"))
The formula is in a different sheet, same workbook though, let's call it "sheetResult". Basically it looks-up values and returns them if there is a match. There are two things I would like to achieve with it further. I need it to be an array so that it applies to all of the rows and I need it to return only the unique values found, I have tried the following but it does not work.
=ARRAYFORMULA(IF(A2:A = "" , , TEXTJOIN(", ",TRUE,UNIQUE(QUERY('sheetName'!B2:F,"SELECT F WHERE B = '"&$A2&"'"))) )) --> not sure what syntax to use
I tried filter but filter just returns all of the info stacked up, need the formula to return the data considering the rows in which the lookup value is held.
EDIT: Added a link to shared file to better describe the question.
I want to make the formula in Y3 on the "Students" sheet apply to all of the cells below it, much like an array formula does.
Example
After further studying your situation I came with a simple fix based on your original formula. I understand that you want to apply the Y3 formula to the whole table, but without altering its behaviour. I assume that the only moving part would be the students ID (Column A). Then you only need to modify your formula to lock the fixed variables with something like:
=TEXTJOIN(" -- ",TRUE,UNIQUE(QUERY('.data'!$B$2:$F,"SELECT F WHERE B = '"&A3&"'")))
After you write that on Y3 you would need to select it and drag it down to fill the table. Please leave a comment if you need further help.

Cell Variable in google sheets formula

I have a couple filtering formulas in Google sheet and would like edit them with another variable.
The filter is for example (it shows all non empty cells form a row):
=FILTER('Data Input'!$A$3:$A$9781; NOT(ISBLANK('Data Input'!$X$3:$X$9781)))
The X should be a variable that I can set from a different cell. I was trying stuff like INDEX
=FILTER('Data Input'!$A$3:$A$9781; NOT(ISBLANK('Data Input'!$INDEX(I13)$3:$INDEX(I13)$9781)))
but this just returns an error. Does anyone know how I can pass cell reference variables in a filter function?
It's hard to know for sure, but I believe you're looking for OFFSET rather than INDEX. OFFSET will allow you to enter integers in a cell which you would reference in your filter formula. Those integers would allow you to adjust which column you're using to check for NOT(ISBLANK...) which is what it looks like you're trying to do.
Maybe this will work, I13 will have the value of the column index (Column X = 24)
NOT(ISBLANK(OFFSET($A$1,2,$I$13-1):OFFSET($A$1,9780,$I$13-1))
OFFSET($A$1,2,$I$13-1):OFFSET($A$1,9780,$I$13-1) Should evaluate to $X$3:$X$9781 while I13 = 24

Index match find closest value with multiple search criteria

I am trying to find a closest absolute value with index match. I looked at several other posts like here but what i am trying to do is a bit different as i want to add multiple search criterias.
As you can see , I am trying to get the absolute closest time for a specific person.
I am using the formula =index(C2:C21,match(F4,B2:B21,-1),match(E4,A2:A21,0)) and I had to copy column B in column C to make my 1st match work. The result is shown in G4. Unfortunately I am struggling to get the correct result.
Effectively I would like use the formula that was posted in the previous post (see link at the top) =INDEX(E2:E21,MATCH(TRUE,INDEX(ABS(D1:D21-I4)=MIN(INDEX(ABS(D2:D21-I4),,)),,),0))
with with a search criteria (the name of the person).
Any help would be much appreciated
Thank you
Thanks #avram
I still end up with some cases where the formula does not work. See below. in G6 and G7 i should get 10:25. (You can ignore column A)
Try this formula in G4,
=index(C$2:C$21, match(min(index(abs(index(C$2:C$21+(B$2:B$21<>E4)*1E+99, , )-F4), , )), if(B$2:B$21=E4, abs(C$2:C$21-F4), 1E+99), 0))
This will work in either google-sheets as a standard (non-array/non-CSE) formula or excel as an array (CSE) formula.
If anyone else wants to tackle this problem with a more elegant formula, you can copy the sample data from this publicly shared google-sheet.
Index match find closest value with multiple search criteria
Perhaps this may exempt a fourth person from retyping the same tired data that the op delivered in image(s).
A very simple approach using a "helper" column with data like:
We want the closest absolute match for larry to 10:15 AM. We enter larry in E1 and 10:15 AM in F1
Then in D2 we enter:
=IF(A2=$E$1,ABS(B2-$F$1),"")
and copy downward. (this is the absolute difference for larry) Finally in E2:
=INDEX(B:B,MATCH(MIN(D:D),D:D,0))
With bigger tables having more columns, it is very easy to add additional criteria if needed.
This answer uses Array Formulas which must be entered using CTRL+SHIFT+ENTER. It's kind of complicated, so I'll do my best to explain and will revise if necessary. Here's a screenshot:
Here is the formula in its raw form; names are entered in column A, Times in Column B.
=INDEX(B1:B7,MATCH(MIN(IF(A1:A7=D2,ABS(E2-B1:B7),"")),IF(A1:A7=D2,ABS(E2-B1:B7),"")))
As you might suspect, it uses INDEX/MATCH to get the job done, but the key is using an IF statement to generate both the search criteria and the array that the MATCH function searches within. Let's break it down.
Sec 1, Match Search Array
IF(A1:A7=D2,ABS(E2-B1:B7),"")
This creates the Search array for the match function. If the name in D2 (our criteria) is equal to the name in the search array, it return the absolute value of the difference between the criteria time and the time in the array we're searching. Otherwise it returns a blank value. Do not use 0 for this as it will skew the match result.
Sec 2, Match Search Criteria
MIN(IF(A1:A7=D2,ABS(E2-B1:B7),""))
This tells us the smallest value in the above array. We use this value as the search criteria in the MATCH function.
Sec 3, putting 1 & 2 Together
MATCH(MIN(IF(A1:A7=D2,ABS(E2-B1:B7),"")),IF(A1:A7=D2,ABS(E2-B1:B7),"")) This searches for the smallest abs difference defined in Section 2 within the array created in Section 1 and returns the row number.
Sec 4, Indexing the times
=INDEX(B1:B7,MATCH(MIN(IF(A1:A7=D2,ABS(E2-B1:B7),"")),IF(A1:A7=D2,ABS(E2-B1:B7),"")))
This returns the time value from column B in whatever row is identified by the Match function above.
Hopefully this all makes sense. Remember to enter it as an array formula.

Resources