Multiply select value from QUERY - google-sheets

I have created a named range called coins and have the following query:
=QUERY(coins,"SELECT C WHERE A = '"&B17&"' ")
which returns the correct values. If I want to multiply this number by e.g. 2 and write the following:
=QUERY(coins,"SELECT C*2 WHERE A = '"&B17&"' ")
my cell is replaced with product(2()) and the correct value is placed at the underneath cell.
I have tried also:
=QUERY(coins,"SELECT product(C,2) WHERE A = '"&B17&"' ")
but had no correct result.
How do I get the value of the multiplication on that specific cell and not the one underneath?

try like this:
=QUERY(coins, "SELECT C*2 WHERE A = '"&B17&"' label C*2''")

Related

How to subtract range from last non empty cell to first?

I am a beginner in google sheets and I couldn't get around this formula. I have range of cells and I want to subtract last non empty cell to first cell (Z-A), here is the image:
As the values are updated in columns C, D, E and so on. I want to get the last non empty cell (from right) and subtract the values by moving backward (left). Like this:
sub = 10(Column G)-0(Column F)-10(Column E)-0(Column D)-10(Column C)
Can we devise a formula which will get the last non empty cell and subtract values until the first value? Here is the link to the sample sheet Thank you
try:
=LOOKUP(1, INDEX(1/(C2:F2<>"")), C2:F2)-(SUM(C2:F2)-
LOOKUP(1, INDEX(1/(C2:F2<>"")), C2:F2))
Suggestion: Use a custom function
You may use the following script as a custom function to get the difference between the value of the last cell and the sum of the other cells:
function SUBTRACTFROMLASTNUMBER(data) { //you can rename the custom function name
var sum = 0;
var data2 = data[0].filter(x => {
return (x != "") ? x : null;
}); //filtered data
var lastNumber = data2.pop(); //last number
data2.map(x => sum += x); //sums the remaining values
return (lastNumber - sum); //returns the output
}
This custom function extracts the selected data from the sheet and then separates the value of the last cell using pop() and then filters and sums the remaining data using filter() and map() and then subtracts the sum from the value of the last cell.
Usage
You may use this function as:
=SUBTRACTFROMLASTNUMBER(<range>)
Reference:
How to Manipulate Arrays in JavaScript

How to have a text output when a formula is true in google sheets

I want to display a letter grade based on a percentage grade. So Say one cell (A1) has a value of 96% and based on A1's value the second cell (A2) would Give an output of "A".
I've tried =if(ISBETWEEN(A1,90%,100%)=TRUE),,"A" (this formula would go into cell A2)
and if anyone could help me with having multiple if formula statements and putting them in one cell.
A = 100%-90%
B = 89%-80%
C = 79%-70%
D = 69%-60%
F = 59%-0%
try:
=INDEX(IFNA(VLOOKUP(A2:A, {0,"F"; 0.6,"D"; 0.7,"C"; 0.8,"B"; 0.9,"A"}, 2, 1)))

How do I get a function to return values in adjacent cells instead of being printed below the cell where the function is written?

I have a table of teams, names, and roles. I am trying to move that data to a separate table, but I want to write a query that returns the values in adjacent cells as opposed to directly underneath which I think is the default.
Here is a picture of the table
=QUERY(A2:C9, "select B where A = 'Bears' and C = 'Coach'", 0)
// returns coach name for team 'bears'
=QUERY(A2:C9, "select B where A = 'Bears' and C = 'Player'", 0)
// returns all player names for team 'bears'
The first query achieves what I want because there is only one coach on each team to return, but the second query does not achieve what I want which is to return the values sideways to so fill in the Player1-3 columns and not impede the row beneath.
delete everything in range E2:I. then...
paste in E2 cell:
=UNIQUE(A2:A)
paste in F2 cell and drag down:
=FILTER(B$2:B, A$2:A=E2, C$2:C="coach")
paste in G2 cell and drag down:
=TRANSPOSE(FILTER(B$2:B, A$2:A=E2, C$2:C="player"))
UPDATE:
=TRANSPOSE(QUERY(Players!A:I, "select I where G = 'player' and A = "&
QUERY(Teams!A:F, "select A where F = '"&C2&"'", 0), 0))

How to conditional format merged and regular cells

I have a google sheet that I want to add a conditional formatting, but the merged cells kinda of get in the way.
In my spreadsheet, I have the columns B,C,D and E where i'm using a formula in column B for when columns C,D and E are "done" column B gets a green background. The problem is, for some rows, columns D and E are merged.
This is the formula I'm using in column B
=and(C:C="done",D:D="done")
My desired result is: When the columns D and E are not merged, column B only gets the green background if columns C,D and E are "done", or else, it stays blank.
When D and E are Merged : B only gets green background if C and DE are "done", or else, stays blank.
Thanks in advance!!
If E always has a non-empty value when D and E aren't merged, you can use that to check for when E is blank using ISBLANK(E:E):
=AND(C:C="done", D:D="done", OR(E:E="done", ISBLANK(E:E)))
Otherwise, there isn't a way to test if a cell is part of a merged range without using a custom function, which is far less efficient, but could technically work with the assistance of a new helper column (e.g. column Z):
/**
* #customfunction
*/
function ISMERGED(cellAddress) {
var cell = SpreadsheetApp.getActiveSheet().getRange(cellAddress);
return cell.isPartOfMerge();
}
Where column Z (or whatever you choose for your helper) has the following in every relevant row (assuming data starts in row 1):
=ISMERGED(ADDRESS(ROW(E1), COLUMN(E1)))
=ISMERGED(ADDRESS(ROW(E2), COLUMN(E2)))
=ISMERGED(ADDRESS(ROW(E3), COLUMN(E3)))
...and so on.
And then for formatting B, use:
=AND(C:C="done", D:D="done", OR(E:E="done", $Z:$Z))
WARNING: If you toggle between merging and unmerging, Z wont contain the correct values immediately, though, because custom functions only re-compute when input changes (and the address of the cell wont in this case).
Update
Here's how you could compute your helper for the whole column downward, by row, by just putting the value in the topmost cell (ex: =ISMERGED("E:E") in cell Z1):
/**
* #customfunction
*/
function ISMERGED(rangeAddress) {
var range = SpreadsheetApp.getActiveSheet().getRange(rangeAddress);
var numCols = range.getNumColumns();
var numRows = range.getNumRows();
var result = [];
for (var i=0; i < numRows; i++) {
var rowRange = range.offset(i, 0, 1, numCols);
result.push(rowRange.isPartOfMerge());
}
return result;
}
best you can get is:
=OR(AND(C:C="done", D:D="done", E:E="done"),
AND(C:C="done", D:D="done", ISBLANK(E:E)))
which will work unless 4th row:
but you could pre-populate the whole E column with =CHAR(1) and then:

OR Function of Excel with Error Values

I want to apply one OR Function in excel with some cells, but Excel is having #N/A(Error Value) in the containing cells, where i want to apply the formula.
Is it possible to apply OR Formula with the cells containing Error Values.
=OR((A1 = "T"),(B1 = "T"),(C1 = "T"))
You can use the IFERROR function (reference) to capture any errors in your source cells and replace them with a default value, say "F":
=OR((IFERROR(A1, "F") = "T"),(IFERROR(B1, "F") = "T"),(IFERROR(C1, "F") = "T"))

Resources