Struggling with arrayFormula and vlookup with match to reference data in another sheet tab to pull a percentage based on row and column membership.
I currently have: =ArrayFormula(vlookup(Orange&7,{A1:A&B1:B,C1:E},match("Skill 3",A1:E1,0)-1,0))
In the shared Google sheet, I have placed notes and explanations. This is a reference sheet for a game, where it refers to Hero skills statistics.
MISSION: Using inputted Hero Class "colour" and "Skill Level" get the "percentage" from the appropriate skill column. This will be needed 3 times to cater for the 3 different skill types in question.
Here is the sheet: TEST Sheet
Approach
Creating a VLOOKUP using more than one criteria will require a helper column made by the concatenation of the two(or more) criteria.
In your case you should build a column that concatenates the Color & Level. Your Lookup will search that value and return the corresponding percentage in the 4th column.
Having your table in Hero Lead like this:
+==========================================+
| A | B | C | D | E | F |
+------+-----+-----+-------+-------+-------+
|Lookup|Class|Level|Skill 3|Skill 4|Skill 7|
+------------------------------------------+
You can use this formula to retrieve the correct value of Skill 3
=VLOOKUP("Orange"&7,'Hero Lead'!A:D,4,0)
Just replicate the formula with the other parameter to retrieve the correct percentage level.
Here is a solution:
=IFERROR(
INDEX(
QUERY(
'Hero Lead'!$A$2:$E,
"select C, D, E
where A = '" & $C$36 & "' and
B = " & G36,
-1
),
0,
MATCH(
"Skill " & F36,
'Hero Lead'!$C$1:$E$1,
0
)
),
0
)
This gets you the right skill's boost from the row filtered using QUERY by level and colour.
If you need all three at once for fixed colour and fixed level (in a column thus TRANSPOSE):
=TRANSPOSE(
FILTER(
'Hero Lead'!$C$2:$E,
'Hero Lead'!$A$2:$A = $C$36,
'Hero Lead'!$B$2:$B = G36
)
)
or:
=TRANSPOSE(
QUERY(
'Hero Lead'!$A$2:$E,
"select C, D, E
where A = '" & $C$36 & "' and
B = " & G36,
-1
)
)
Related
For this sample table:
A
B
C
D
E
1
Range!A1:C5
URL1
= Formula here
2
URL2
3
URL3
4
...
I have this working formula in C1:
={IMPORTRANGE(B1, A1); IMPORTRANGE(B2, A1); IMPORTRANGE(B3, A1)}
A1 contains the range to pull from the target Sheets.
Links to the target Sheets are found in column B.
(This is a simplified example. My actual Sheet has 21 entries in column B.)
Question:
If I will have to add/remove URLs in column B, I have to adjust the formula in C1 and add/remove IMPORTRANGEs.
I would like to have a formula that automatically adjusts to the entries in column B.
Solutions tried:
I tried this, but it did not work:
={JOIN("", ARRAYFORMULA(IF(LEN(B1:B), "IMPORTRANGE(""" & B1:B & """, """ & A1 & """); ", "")))}
The JOIN function returns a text that should be identical to what the array { ... } parses as a formula. But it doesn't. Wrapping it with INDIRECT also does not work.
Any suggestions on how I could make this work?
if by "working formula" you mean valid formula that returns data then only thing you can do is hardcode it like this:
=QUERY({
IFERROR(IMPORTRANGE(B1, A1), {"","",""});
IFERROR(IMPORTRANGE(B2, A1), {"","",""});
IFERROR(IMPORTRANGE(B3, A1), {"","",""})},
"where Col1 is not null", )
A1:C5 = 3 columns = {"","",""}
you can generate formula dynamically with arrayformula but the result will be always a text string and not active formula. tho if you wanna go this way you will need a script that will convert your text string into active formula. example:
https://stackoverflow.com/a/73119313/5632629
https://stackoverflow.com/a/61819704/5632629
I am trying to get a google sheet to search for a specific cell in a table. The headers change so it might be A6 one week and then A9 the other and so on.
Once it's found that row, I want it to search and pull all of that departments names and data for the column its matched with.
I am 23 sheets in and my heads hit a brick wall and I just can figure it out.
You can try:
=QUERY({A:B,INDEX(A:G,0,MATCH(D25,1:1,0))},"SELECT * WHERE Col2='" & LOWER(F25) & "'")
Note - you should remove unnecessary spaces. In sample data, they were in cells C1 and D25.
Try this:
=QUERY(
FILTER(
IFS(
TRIM(1:20) = "", 0,
ISNUMBER(1:20), 1:20,
True, LOWER(TRIM(1:20))
),
1:1 <> ""
),
"SELECT Col1, Col2, Col" & MATCH(TRIM(D25), ARRAYFORMULA(TRIM(1:1)),) & "
WHERE Col2 = '" & LOWER(F25) & "'",
1
)
You can use a combination of CHAR(MATCH...)) and Query formula to get this
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, "&CHAR(MATCH("Log 4",'Sheet Name'!A1:G1)+64)&" WHERE B='w'")
Above formula only works till column Z, but thanks to Kishkin's comment below, you can use it beyond Z like this:
=QUERY('Sheet Name'!A1:G20,"SELECT A, B, `" & =REGEXEXTRACT(ADDRESS(1, MATCH("Log 4",'Sheet Name'!A1:G1), 4), "\D+") & "` WHERE B='w'")
You use SUBSTITUTE instead of REGEXTRACT too. You can refer to this Question.
the CHAR(MATCH...)) gets the column name of the desired Log
you can then use the column name to include that column in Query select statement
In the MATCH formula, you can also dynamically Match for a cell reference instead of specifying "Log 4" manually
Note: This is basically splitting the Query formula and concatenating it with another formula. So the &, ' and " symbols are really important
Sample Screenshot:
I have a Google Sheets database that I want to query. I want the query to be based on data in columns B, C, and D and return all data if the conditions are met. I have input cells for the search criteria for those three columns, and I'd like the query to do the following:
Ignore search criteria where there is no value entered in the search cell
Use AND logic where there is a value in a given cell
For example, search criteria in input cells:
B = "1"
C = Blank
D CONTAINS "the"
I want the query to return data where C is anything and B = "1" and D CONTAINS "the".
Another example:
B = "1"
C = "E"
D CONTAINS "the"
I want the query to return data where all three conditions are met
I'd like D to not be null in all cases.
I'm having trouble incorporating the empty criteria into the query. I've tried dynamically using AND/OR depending on whether there's data in a given search cell, but I can't get it to work.
So, I created a crazy-long query to account for all possible combinations with B, C, and D. This works, but I want to incorporate more search criteria, and this equation becomes exponentially more complicated with 4, 5 or more search criteria.
Here is an image of the query input and query results for the first example above (I'm not sure why some of the values in the Name column don't contain "the").
Image of Query Sheet
And here's an image of the database that I'm querying against:
Image of Database Sheet
Here is the equation I'm using:
=if(and(B4="",C4=""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and D IS NOT NULL order by D asc",1),
if(and(B4<>"",C4=""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and B matches '"&B4&"' and D IS NOT NULL",1),
if(and(B4="",C4<>""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and C matches '"&C4&"' and D IS NOT NULL",1),
if(and(B4<>"",C4<>""),query(DATABASE!A1:E,"SELECT * WHERE D contains '"&D4&"' and B matches '"&B4&"' and C matches '"&C4&"' and D IS NOT NULL",1),
if(D4="",query(DATABASE!A1:E,"SELECT * WHERE B matches '"&B4&"' "&IF(AND(B4<>"",C4<>""),"AND","OR")&" C matches '"&C4&"' and D IS NOT NULL",
1),FALSE)))))
My ask: I'd like to simplify this equation so that it can be extended to multiple search criteria (more than 3). Thank you for your help!
Try this:
=QUERY(
DATABASE!A:E,
"WHERE D IS NOT NULL"
& IF(B4 = "",, " AND B = " & B4)
& IF(C4 = "",, " AND C = '" & C4 & "'")
& IF(D4 = "",, " AND D CONTAINS '" & D4 & "'")
& " ORDER BY D",
1
)
[Goal]
I'm trying to count the number of tickets per employee in one column that has a status with either "Finished," "Finished (Scope)," or "Routed (Sales)" for a specific week. In another column I also want to count the number of tickets for a specific week without criteria. The data that I'm pulling from to count the tickets has the following column names.
Column A: Date,
Column B: Ticket ID,
Column E: Employee,
Column H: Finished Week
Column K: Week
In the formula, you'll notice that it's referring to cell H1, which the cell contains the current week which is this formula: =TODAY()-MOD(TODAY()-2,7)-1
[Current Formula]
=QUERY('Data'!$A$3:$J,"Select E,
COUNT(B) where D matches 'Finished|Finished \(Scope\)|Routed \(Sales\)'
AND H = "&H1&" GROUP BY E LABEL COUNT(B) 'Total Finished Tickets'",0)
[What it should look like]
I've created a sample spreadsheet that you can refer to.
Link: https://docs.google.com/spreadsheets/d/1MQLgt_SSbUIKv1rEwx-Y21hooxNOOgcUm_j1rFehHdg/edit?usp=sharing
[Issue]
I was able to create a table that counts the number of tickets per employee with the status as "Finished" OR "Finished (Scope)" OR "Routed (Sales)." Which is the "Current Result" table (Link: https://docs.google.com/spreadsheets/d/1MQLgt_SSbUIKv1rEwx-Y21hooxNOOgcUm_j1rFehHdg/edit#gid=0).
However, as I tried to add another count criteria, it gave me errors and I don't understand how to properly make this work. I wanted to look like the table of the title "Ideal Result" in the shared link. Can someone please help?
You can use the pivot clause to get a breakdown by the Status column like this:
=query(
Data!A3:J,
"select E, count(E)
where H = " & E4 & "
group by E
pivot D
label E 'Employee' ",
0
)
The downside is that the grand total must then be calculated separately, but that can be done with a simple sum() formula.
Alternatively, get the totals first, and then do a lookup to get the number of finished tickets, like this:
=query(
Data!A2:J,
"select E, count(D)
where H = " & E4 & "
group by E
label E 'Employee', count(D) 'Total new tickets' ",
0
)
=arrayformula(
iferror(
vlookup(
E12:E,
query(
Data!A2:J,
"select E, count(D)
where H = " & E4 & "
and (D = 'Finished' or D = 'Finished (Scope)')
group by E
label count(D) 'Finished tickets' ",
1
),
2,
false
)
)
)
Note that this serves just to illustrate how to aggregate the data into a report. Your question leaves it unclear as to which status values should be counted for each type of aggregation. No rows with status Routed (Sales) appear in the data, and I cannot see how the expected results you show could be derived from the data.
See your sample spreadsheet.
H1, which the cell contains the current week which is this formula
=TODAY()-MOD(TODAY()-2,7)-1
You may want to try the weeknum() function.
To get two independent counts, you can't use a Where clause because that would exclude cases from both counts, but you could use the fact that Query does not count empty cells something like this:
=ArrayFormula(query({if(regexmatch(D3:D,"Finished$|Finished \(Scope\)$|Routed \(Sales\)$"),true,),E3:E,if(K3:K>=H1,true,)},"select Col2,count(Col3),count(Col1) where Col2 is not null group by Col2 label count(Col1) 'Finished', count(Col3) 'New'",1))
Supposing all I have is the column A below
+ +
A | B | C
+--------------|---------|----------+
| |
X, Y, Z | X | 3
| |
X, Z | Y | 2
| |
X, Y | Z | 2
+ +
How do I generate columns B and C - where the B column grabs the unique elements from A, and the C column generates a count of those values.
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN(",",A:A),",")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))
QUERY function
TRANSPOSE function
SPLIT function
JOIN function
Without hidden cells is possible to do it with an alternative method than the one proposed by Adam (that did not work in my case).
I have tested it with google spreadsheets (from data coming from a google form using multiple selection answers):
=UNIQUE(TRANSPOSE(SPLIT(JOIN(", ";A2:A);", ";FALSE)))
Explanation goes as follows:
JOIN to mix all the values from the A column (except A1 that could be
the header of the column, if not, substitute it by A:A) separated by
a coma
SPLIT to separate all the mixed values by their comas
TRANSPOSE to transformate the column into rows and viceversa
UNIQUE
to avoid repeated values
Take into account that my "," coma includes and space character i.e., ", " to avoid incorrect unique values because "Z" y not equal to " Z".
Is it possible to create a hidden sheet?
If yes, 1) use the SPLIT() function to separate the values into columns and 2) use COUNTIF() on the hidden sheet to get the number of values