Is it possible in Google Sheets or Excel to map a key to a table? For instance, vlookup(A1, someTable, 2) returns {{1;2;3},{4;5;6}}, where the cell A1 is mapped to the table {{1;2;...}}
This is the equivalent to Python's:
some_dict = {
1: {11, 111, 1111},
2: {22, 222, 2222},
3: {33, 333, 3333}
}
More background: I have a list of math sequences. It would be convenient to access them through indices.
What I Tried
In this example sheet:
I tried
=hlookup(1, A:C, 2) // Expected output: {{1;2;3;4}, {1;1;2;3}}
But it seems like the lookup functions do not handle expanded arrays.
Related
I'm trying to set up a sortn function with a filter inside, but for some reason this function isn't working:
=sortn(filter(AssessScores,AssessScoreStudent=C4,AssessOppor=A$1),1,0,TimestampScores,false)
I get an error: "Error SORTN has mismatched range sizes. Expected row count: 2. column count: 1. Actual row count: 300, column count: 1."
This works:
=sortn(filter(AssessScores,AssessScoreStudent=C4,AssessOppor=A$1),1,0)**
So something is going wrong when the sort column is added.
All of the named ranges are on the same workbook and sheet, the function is running in another sheet of the workbook.
Any ideas on how to fix this?
If you give sort() or sortn() an array as the sort column, the array must be as tall as the data to be sorted. Use something like this:
=sortn(
filter(AssessScores, AssessScoreStudent = C4, AssessOppor = A$1),
1, 0,
filter(TimestampScores, AssessScoreStudent = C4, AssessOppor = A$1),
false
)
I have two data sets:
Data set 1 is data from our Sales team
Data set 2 is data from our Finance team
The common element between these two sets is the Invoice ID column (col A in data set 1 and col E in data set 2). However, in data set 1, this data is stored as an array, and in data set 2, each value of the array is displayed on its own row.
GOAL
I'd like to be able to enrich data set 2 (cols F & G) with the data from data set 1, however, I'm having trouble making that work. I've tried using =FILTER(A3:A7, REGEXMATCH(TEXT(E3, "0"), TEXT(ARRAYFORMULA(SPLIT(A3:A7, ",")), "0"))), but that gives me the following error: "FILTER range must be a single row or a single column.". I understand that this happens because of the SPLIT function, but I don't know how else to go about this.
The sheet can be found here.
Any help is super appreciated.
I've added a new sheet ("Erik Help") to your sample spreadsheet. The following single formula will produce all results for F3:G ...
=ArrayFormula(IF(E3:E="",,VLOOKUP("*"&"%"&E3:E&"%"&"*",{REGEXREPLACE("%"&A3:A&"%","[,\s]","%"),B3:C},{2,3},FALSE)))
The % symbol is just used to "pad" every element from Col A and Col E in something unique in order to differentiate search term 1 from, say, 14 (i.e., the VLOOKUP will search for %1% instead of just 1, which will not be found in %14%, etc.) The % symbol has no special meaning; it could have been any unique character we were sure wouldn't normally turn up in Col A or Col E.
REGEXREPLACE replaces all commas and spaces with this special % character in addition to the front and back placements. So a Col-A list like 1, 14 would be seen by sheets at this point as %1%%14%.
The * is a wildcard symbol that, appended front and back to the search term, which will allow it to be found in elements of Col A that contain lists.
Results from the second and third columns (e.g., {2,3}) of the virtual array are returned.
Give a try on-
=FILTER($B$3:$B$7,ArrayFormula(MMULT(--(SPLIT($A$3:$A$7,", ")=E3),SEQUENCE(Columns(ArrayFormula(SPLIT($A$3:$A$7,", ")))))))
I'm trying to deduplicate based on the values in a single column when using Google Sheets' query() formula.
query('Data'!A2:D, "select A, B, C, D")
In this example, I'd like to pull out the first instance of each pet location -- basically, the data deduplicated by the Location in column C. So something like:
query('Data'!A2:D, "select A, B, C, D where C is unique")
Is there any way to do this gracefully within Google Sheets?
Example sheet with desired output here:
https://docs.google.com/spreadsheets/d/10lvghkMgw1eOLeUp0TmyWzohWOGhQbZisNwrIujCaXA/edit?usp=sharing
use:
=SORTN(A2:D, 9^9, 2, 3, 0)
9^9 = all rows
2 = grouping mode
3 = column number
0 = sorting
Try this:
=ArrayFormula({"Name","Type","Location","Instance Date";VLOOKUP(UNIQUE(FILTER(Data!C2:C,Data!C2:C<>"")),{Data!C2:C,Data!A2:D},{2,3,4,5},FALSE)})
Essentially, this formula sets up your headers, then runs the list of unique locations through a VLOOKUP using a virtual array formed from the locations appended in front of all other data, returning all other data. What you wind up with is first match.
NOTE: Your date returns may come through as raw data (i.e., numbers in the 40,000 range); if so, just format that column in the date format of choice.
I want to extract certain rows from this dataframe with the filter function:
Now I want to sort the extracted rows but the condition should be column G. Standard sort takes column F as condition.
But I want it to be sorted at column G:
See if this works
=sort(filter(B3:C, regexmatch(C3:C, "Apple|Cat|Florida")), 2, 1)
In Google Sheets is it possible to get all the values in the rows if a column header is the same?
So if I have
I want to query for "Type" and get the unique values as "Manhole, Overflow, Scour Manhole, Unknown"
If I transpose it I can do something like =VLOOKUP(B5,Sheet10!1:1000,2,False) and then have to figure out a way to get it to concatenate all values in subsequent fields of that row but it's better to avoid this.
You can use the following command
=textjoin(", ", 1, Unique(E2:E7))
Unique function returns unique value from the range and textjoin joins the returned value with your provided delimiter.
is it possible to get all the values in the rows if a column header is the same?
=UNIQUE(INDIRECT(ADDRESS(2, MATCH(E1, 1:1, 0), 4)&":"&
ADDRESS(ROWS(A2:A), MATCH(E1, 1:1, 0), 4)))