I'm trying to use Query and IMPORTRANGE to get data from another google sheet when a checkbox in the column is TRUE. But I'm just getting an error..
Found this solution:
=QUERY(IMPORTRANGE("G-Sheet URL", "TAB & range"), "where Col15=TRUE", 1)
My code:
=QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o/edit#gid=0", "Spelbricka!C6:C12"), "where Col6=TRUE", 1)
It just gives me error.
Anyone?
Thanks on behalf / R
To import a range if one of your cells in that sheet is set to true, you will be wanting to set everything with an IF condition and wrap the IMPORTRANGE with an ARRAYFORMULA function. ARRAYFORMULA will let you display an array of values in differnt rows and columns rather than a single one avoiding therefore errors (as IF itself would just accept returning a single value), making your non-array function into an array function.
Moreover, with this you can also choose to return another IMPORTRANGE is the checkbox is unmarked. In the following example I'm importing a range if the cell B1 checkbox is ticked.
=(IF(B1=True,ARRAYFORMULA(IMPORTRANGE("SHEETURL","Sheet1!C6:C12")),""))
first run this in any cell and allow access:
=IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A6")
then try:
=QUERY(IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A6:E12"); "select Col3 where Col6=TRUE"; 0)
notice the range A6:E12 where we return column C only if column E equals TRUE
UPDATE:
use in C6:
=IF(
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!"&ADDRESS(MATCH(A6;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A:A"); 0); 3))=TRUE;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!"&ADDRESS(MATCH(A6;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A:A"); 0); 3)&":"&ADDRESS(MATCH(A6;
IMPORTRANGE("1ztQla9sOO7xkQdSAMOKHcas81H4jVbYjg9tVi9w1u0o";
"Spelbricka!A:A"); 0)+6; 3)); )
then select C6
copy it with CTRL + C
and paste with CTRL + V into C15, C24, etc.
Related
I got this "table" (page raids) and want to do function formating for highlight duplicates (yellow).
Google Sheet
In this case there is match in 2 strings (dark blue):
Name1
Gunslinger
I already try functions VLOOKUP, Match, Filter, countifs and Quary (dont know how it works...) with Index function, but nothing seems work as I want ...
VLOOKUP and Match only gives first value.
Filter doesnt work on this strucker or I dont know how to use it in this case (I know how it works in normal table)
Can someone tell me what function conbination to use that can be put in Function formating ?
Formating for each row:
Example: =IF(B3>0;IF(B4<1490;TRUE;FALSE);FALSE)
ECT.
After some searching and testing, I came up with this:
=ArrayFormula(SUM(IFERROR(FIND(B2&B3;MID(CONCATENATE((TRANSPOSE($B$2:$I$33)));SEQUENCE(LEN(CONCATENATE((TRANSPOSE($B$2:$I$33))));1;1;1);len(B2&B3)))=1)*1))>1
Still need to make the functions more tidy (picture 2 and 3).
See if this is what you are looking for?
Conditional formatting with Custom formula in Range: A2:H:
=LAMBDA(NAME,OR(A1=NAME,A2=NAME,A3=NAME))("Gunslinger")
or do you means you want to highlight only duplicates?
If that is the case, you may try this formula:
=LAMBDA(DATARANGE,
LAMBDA(FLAT,
{{"Team","Duplicate"};{UNIQUE(FLAT),BYROW(UNIQUE(FLAT),LAMBDA(NAME,COUNTIF(FLAT,NAME)>1))}}
)(
QUERY(FLATTEN(
BYCOL(DATARANGE,LAMBDA(C,
BYROW(C,LAMBDA(R,
IF((ROW(R)+1)/4=INT((ROW(R)+1)/4),R,"")
))
))
),"SELECT Col1 WHERE Col1 IS NOT NULL",0)
)
)(A2:H)
This formula returns an array of unique Names with checking if there are Duplicates in the given datarange.
Combine this with the 1st formula should be able to highlight repeated data sets from your table.
Solution for 2 criteria matching:
The formula inside the image form the table of unique match results,
use that result with OR(), XLOOKUP(), OFFSET(), INDEX() as below for the final formula to put into the custom formula in conditional formatting.
=LAMBDA(RESULT,
LAMBDA(NAME,DUP,KEY,
LAMBDA(KEY_M2,KEY_M1,KEY_P1,
OR(
XLOOKUP(KEY_M2&"&&"&KEY_M1,NAME,DUP,FALSE),
XLOOKUP(KEY_M1&"&&"&KEY,NAME,DUP,FALSE),
XLOOKUP(KEY&"&&"&KEY_P1,NAME,DUP,FALSE)
)
)(IFERROR(OFFSET(KEY,-2,0),""),IFERROR(OFFSET(KEY,-1,0),""),IFERROR(OFFSET(KEY,1,0),""))
)(INDEX(RESULT,,1),INDEX(RESULT,,2),A2)
)(
LAMBDA(DATARANGE,
LAMBDA(FLATCLASS,
{{"Name","Duplicate"};{UNIQUE(FLATCLASS),BYROW(UNIQUE(FLATCLASS),LAMBDA(NAME,COUNTIF(FLATCLASS,NAME)>1))}}
)(
QUERY(FLATTEN(
BYCOL(DATARANGE,LAMBDA(C,
BYROW(C,LAMBDA(R,
IF((ROW(R)+1)/4=INT((ROW(R)+1)/4),IF(R="","",INDEX(C,ROW(R)-2)&"&&"&R),"")
))
))
),"SELECT Col1 WHERE Col1 IS NOT NULL",0)
)
)($A$2:$H)
)
I've been trying to figure out what i'm doing wrong here when i'm doing the sumif formula's in b2,c2,d2
I have a lot going on, I realize. The data we are looking at, is between L5:U21
I have a query in a5 that pulls from l5:U that pairs any data in n5:n,p5:p,r5:r,t5:t to the selected data in the dropdown in a2. This part is working correctly for what I need.
B2 I am trying to extract from the top 3 options in the range b5:J that match a2, and add them together. Ultimately I'd like to do this if they do not have "Left" or "Right" in the J column as well.
To achieve this I pulled the data from b5:I into a sortn function seen in y5.
=SORTN(B5:I,3,,B5:B,false,D5:D,false,F5:F,false,H5:H,false)
and then my SUMIF function is as follows: =SUMIF(Z5:AF,A2,Y5:AE)
C2 is similar to B2, but I only data that matches the selection in a2, but also have "Left" in the J column.
I tried to achieve this with a similar SUMIF function i'm using in b2, but it seems to only pull the left most cell's data in the range given, not the matching column's data. So lets say if e9 = example1, it doesn't then grab the matching 2 in d9, it grabs whatever is in b9 only, and adds that. Which right now, it adds them all. I want to ultimately only pull the top 1, but I cannot even get it working correctly with all of them.
=SUMIF(J5:J,"Left",B5:H)
D2 is the same as C2, but "Right" in the J column.
This is my example / testing document I created to get a closer look at what's going on, if what i'm explaining isn't making a ton of sense.
https://docs.google.com/spreadsheets/d/1eZ7_yOrkoy_PCgcn_YxscPnDCvLXWK48JW-S7DqEgdQ/edit?usp=sharing
Try the following in C2
=QUERY({{B5:C;D5:E;F5:G},{J5:J;J5:J;J5:J}},
"select sum(Col1) where Col2='"&A2&"' and Col3='Left'
label sum(Col1) '' ",0)
For cell D2 all you need to do is use Col3='Right'
=QUERY({{B5:C;D5:E;F5:G},{J5:J;J5:J;J5:J}},
"select sum(Col1) where Col2='"&A2&"' and Col3='Right'
label sum(Col1) '' ",0)
In case you want to add more ranges like columns H-I you would adjust your formula like:
{{B5:C;D5:E;F5:G;H5:I},{J5:J;J5:J;J5:J;J5:J}}
(Do adjust the formula according to your ranges and locale)
SUGGESTION
I was experimenting earlier with SUMIFS & QUERY formulas to no success, as I also have a limited knowledge when it comes to implementing advanced Google Sheet formulas in a complex scenario. What I can suggest you try is by using a Custom Function formula in Google Sheet made possible by Google Apps Script that's integrated to the Google Sheet service.
This custom formula function will filter the range that does not contain Left or Right in column J based on the selected drop-down data, and then it returns the top 3 results in descending order.
The Custom formula Script named as CUSTOM_FUNC
/**
* Filters data in descending order from a range that doesn't contain any Left & Right based on selection in a cell dropdown selection & return the sum of the top 3 result.
*
* #param {B5:J21,A2} reference The range to be used.
* #returns The range and the cell reference to used in filtereing the data.
* #customfunction
*/
function CUSTOM_FUNC(data,dropdown_selection) {
/**Filter data that do not contain Left or Right on column J */
var lvl1 = data.map(x => {return x.toString().includes('Left') || x.toString().includes('Right') ? null : x }).filter(y => y)
/**Further filter lvl1 that matches the drop down selection*/
var res = lvl1.map(d => {
return d.map((find, index) => {return find == dropdown_selection ? d[index-1] : null}).filter(z => z)
});
/**Return the top 3 result in descending order */
return res.sort().reverse().slice(0, 3);
}
The parameters of this customer formula would be:
=CUSTOM_FUNC(data,dropdown_selection)
data
The sheet range (e.g. B5:J21) where the data you'd like to be processed resides.
dropdown_selection
The cell reference of the drop-down selection on your spreadsheet file.
To add this script in your spreadsheet file, copy and paste the script as a bound script in your Spreadsheet file by following this official guide
Demonstration
You can use the custom function formula named CUSTOM_FUNC similarly to how you use another Google Sheet formula on a cell, like this =SUM(CUSTOM_FUNC(B5:J21,A2))
I'm trying to solve why one of the Google Sheets I maintain is failing to operate properly. I've isolated that the issue is with a query
QUERY(Import_MJL!A:BU, "select A where AJ> 0")
For reference the Import_MJL sheet is a static database. The AJ column holds a currency value. When performing an IF function of that column, it returns as TRUE as seen here
if(Import_MJL!AJ2 > 0,1,0)
What could be the reason that the query is not recognizing when my AJ Column is above 0 ?
Screenshot for bellow reference. Row 1 holds the code & row 2 holds the Results (The B2 Cell should result in an array whose length is over 10K but only returns the header. The Import_MJL!AJ2 cell has value 38K and should be a result of the cell on B2)
Screenshot of code and results
Thanks for the time y'all!
Chances are that Import_MJL!AJ2 does not contain a number but the text string $38,738.00 that only looks like a number. Many spreadsheet functions will automatically convert such values into numbers, but query() will not.
You can check whether a value is actually a number with the isnumber() function.
Here's a quick fix to try:
=arrayformula(
query(
{ Import_MJL!A1:AI, value(Import_MJL!AJ1:AJ), Import_MJL!AK1:BU },
"select Col1 where Col36 > 0",
1
)
)
I originally have this formula:
=QUERY('Sheet1'!$C$6:$I, "Select F where D contains '"&$B86&"'")
This is applied to every cell from $B86 down to $B145. Users of the sheet accidentally deletes formula and adding protection isn't an option. So I'm thinking of adding the formula to the header only using arrayformula. However, arrayformula can't be used for query.
QUESTION 1:
Is there any other way around to get the same result when only the header has the formula?
={"Messages Sent";ARRAYFORMULA(QUERY('Sheet1'!$C$6:$I, "Select F where D contains '"&B86:B145&"'"))}
This is kinda what I want to achieve. However, this doesn't fill the data from B87 to B145. I only get the header and result for 1 row below the header.
Explanation
This shows the header ={"Messages Sent";
This is supposed to be the arrayformula ARRAYFORMULA(QUERY('Sheet1'!$C$6:$I, "Select F where D contains '"&B86:B145&"'"))}
This is the data from another sheet 'Sheet1'!$C$6:$I
This is the same data from the current sheet to find F in sheet 1 '"&B86:B145&"'
QUESTION 2: HOW CAN I GET THE ANSWER FROM THE QUERY AUTOMATICALLY SET INTO A NUMBER FORMAT SO I CAN DIRECTLY ADD THEM INSTEAD OF FORMATTING THEM MANUALLY AS NUMBER?
try maybe:
={"Messages Sent"; ARRAYFORMULA(IFNA(VLOOKUP(B86:B145,
{REGEXEXTRACT(""&Sheet1!D6:D, TEXTJOIN("|", 1, B86:B145)), Sheet1!F6:F*1}, 2, 0)))}
I have a spreadsheet with 1 sheet of software version an another sheet of installation records. I want to do a conditional formatting that compares the version of in installation (on column F) to its know latest version number on another sheet ('Software Versions').
Current Solution
I came up with this formular initially:
=AND(F2<>"", F2=G2)
It works. But I need to maintain a column of QUERY results on G2:
=QUERY('Software Versions'!$A$1:$B$8, "Select B where A='" &D4& "' LIMIT 1")
Problem
Now I want to remove the G2 row altogether. I came up with this combined query:
=AND(F2<>"", F2=QUERY('Software Versions'!$A$1:$B$8, "Select B where A='" &D4& "' LIMIT 1"))
But I cannot save it because it is an "Invalid Formula":
Any way to actually do it?
Try use this formula:
=AND(F2<>"", F2=IFERROR(QUERY(INDIRECT("'Software Versions'!$A$1:$B$8"),
"Select B where A='" &D4& "' LIMIT 1 label B ''"),""))
I was able to make conditional formatting with this formula.
Improvements
Use indirect to address another sheet
Use label B '' to prevent header appear as query result
Use iferror(..., "") to be sure no error occurs when no data is found with query
I'm used to the good old VLOOKUP function for my conditional formattings.
The syntax is VLOOKUP(valueOrCell, sourceRange, index, FALSE)
So if the value from first parameter valueOrCell, exists in the sourceRange, return the value at index. FALSE is to have the exact match.
In my example I'm using only a single worksheet, but if you set the sourceRange to different worksheet it works as well.