I'm working on a spreadsheet in google sheets.
I am creating a character sheet for a upcoming pathfinder game and I am currently working on the feats page. I have the page arranged so that Col A is the level in which I will get the feat, Col B is the feat name, Col C is the prerequisites for the feat, and Col D is where I am creating the formula that will tell me if all the requirements have been met.
Level | Name | Prerequisites | Met?
1 | Dodge | None
1 | Mobility | Dodge | Formula
2 | Spring Attack | Mobility | Formula
3 | Whirlwind Attack | Spring Attack | Formula
What I am trying to do is create some sort of lookup. I want to limit the range of level (Col A) based on my characters level (lets use Z3 as the cell reference). So if I am level 2, it will only check feats that are level 2 or less. Then I need to make sure the feat name is listed in the reduced Col B.
If there is a better or easier method than a lookup, feel free to let me know.
So assuming that level is set to 1, the formula for Spring Attack would produce a true statement, and the formula for Whirlwind attack would produce a false, because spring attack isnt taken until level 2, and I am only level 1. Once my level changes to 2, then whirlwind should also read true.
A relevant Google Sheets formula is filter. For example,
=filter(B2:B, A2:A <= 2)
returns the list of entries from column B (feat names) where the corresponding entry in column A (level) is at most 2.
One can apply multiple filters, for example
=filter(B2:B, A2:A <= 2, C2:C = "string")
additionally requires the entry in C to be "string".
When there are no matches, the filter returns N/A. This can be used to produce True/False values predicated on finding at least one cell that meets the conditions:
=not(isna(filter(B2:B, A2:A <= 2, C2:C = "string")))
is True if there was a match and False otherwise.
I have this matrix for key/values
1 | one
2 | two
3 | three
| none
and the VLOOKUP cell
=VLOOKUP(A10,A1:B4,2,false)
If the cell A10 contains any number from 1 to 3 it is ok, but if the cell A10 is empty the VLOOKUP returns: "#N/A" -> _"Error: Did not find value '' in VLOOKUP evaluation."_
Any possibility to make VLOOKUP to work also with empty cells?
I've found a solution here:
=IF(ISNA(VLOOKUP(A10,A1:B4,2,false)), B4, VLOOKUP(A10,A1:B4,2,false))
Check that B4 is the hardcoded position of the "none" text so this is extracted not using the VLOOKUP it self.
I really hope someone comes with something less ugly ;)
Two sheets, one called Core Data, one called Schedule. The Schedule sheet needs to take information about deadlines from Core Data and display it concatenated in deadline-order. (Simple example with numbers and letters instead of dates and tasks given below.)
Here's what I have so far in 'Schedule' (cell B2 specifically in this case):
=JOIN(", ", FILTER('Core Data'!A2:A, 'Core Data'!B2:B=A2))
It's saying no matches are found so I assume this is a problem with the filter component of the formula. However, I've checked the help pages and can't see a problem with the condition I've created.
The formula should:
Get all the values in the given range (cells A2 downward on a 'Core Data' sheet),
Filter them so that only those with certain values are selected. (The information from 'Core Data' should only be selected if the date in the same row on column B matches the date in the cell in the A column on the Schedule sheet.)
Join all these values together and list them as a comma-delimited list.
Example (without dates, for ease):
Core Data sheet:
A | B
-----
a | 5
b | 7
c | 5
d | 3
Schedule sheet (or what it should look like):
A | B
---------
3 | d
5 | a, c
7 | b
Any idea what is going wrong with my formula or if there is an easier way to solve this problem?
The error message I was getting in the cell is:
Error: No matches are found in FILTER evaluation.
It turns out that the cell I was trying this formula on simply had no matches from the filter (no dates corresponded) but instead of returning empty it threw an error. This sounds simple but it's an annoying quirk for me that the cell didn't end up empty which made me assume the formula was at fault.
While the example in the question works you can quickly break it by adding an extra row to the 'Schedule' table with "8" as the value in the A column and the formula in B:
A | B
---------
3 | d
5 | a, c
7 | b
8 | N/A
The "8" throws an error since it isn't found in the 'Core Data'.
Conversely, on my original spreadsheet, When I tried the formula in a cell which did correspond to a noted deadline, it worked.
I found the solution here is to add an IFERROR function to the formula to deal with this.
So a formula that works for this is:
=JOIN(", ", IFERROR(FILTER('Core Data'!A:A, 'Core Data'!B:B=A5)))
One does not use the second IFERROR argument as advised in Google's own helpsheet. I tried putting in an empty array at first ({}) but this threw a different error. It seems if you miss the argument out, the JOIN knows it has nothing to work with and the cell ends up with a nice blank value.
In a Google Spreadsheet: How can I count the rows of a given area that have a value? All hints about this I found up to now lead to formulas that do count the rows which have a not empty content (including formula), but a cell with
=IF(1=2;"";"") // Shows an empty cell
is counted as well.
What is the solution to this simple task?
I just used =COUNTIF(Range, "<>") and it counted non-empty cells for me.
=counta(range)
counta: "Returns a count of the number of values in a dataset"
Note: CountA considers "" to be a value. Only cells that are blank (press delete in a cell to blank it) are not counted.
Google support: https://support.google.com/docs/answer/3093991
countblank: "Returns the number of empty cells in a given range"
Note: CountBlank considers both blank cells (press delete to blank a cell) and cells that have a formula that returns "" to be empty cells.
Google Support: https://support.google.com/docs/answer/3093403
If you have a range that includes formulae that result in "", then you can modify your formula from
=counta(range)
to:
=Counta(range) - Countblank(range)
EDIT: the function is countblank, not countblanks, the latter will give an error.
Here's what I believe is the best solution so far:
=CountIf(ArrayFormula(range<>""),TRUE)
Here's why in 3 easy steps
Step 1: Simple As Pie - Add Extra Column
The answer by eniacAvenger will yield the correct solution without worrying about edge cases as =A1<>"" seems to arrive at the correct truthy/falsy value based on how we intuitively think of blank cells, either virgin blanks or created blanks.
So imagine we have this data and we want the Count of non-blanks in B2:B6:
| | A | B | C |
|---|-------------|-------|---------|
| 1 | Description | Value | B1<>"" |
| 2 | Text | H | TRUE |
| 3 | Number | 1 | TRUE |
| 4 | IF -> "" | | FALSE |
| 5 | IF -> Text | h | TRUE |
| 6 | Blank | | FALSE |
If we relied on Column C, we could get the count of values in B like this:
=COUNTIF(C2:C6,True)
Step 2: Use FormulaArray to dynamically create Extra Column
However, consideRatio's comment is a valid one - if you need an extra column, you can often accomplish the same goal with an ArrayFormula which can create a column in memory without eating up sheet space.
So if we want to create C dynamically, we can use an array formula like this:
=ArrayFormula(B2:B6<>"")
If we simply put it in C2, it would create the vertical array with a single stroke of the pen:
| | A | B | C |
|---|-------------|-------|--------------------------|
| 1 | Description | Value | =ArrayFormula(B2:B6<>"") |
| 2 | Text | H | TRUE |
| 3 | Number | 1 | TRUE |
| 4 | IF -> "" | | FALSE |
| 5 | IF -> Text | h | TRUE |
| 6 | Blank | | FALSE |
Step 3: Count Values in Dynamic Column
But with that solved, we no longer need the column to merely display the values.
ArrayFormula will resolve to the following range: {True,True,False,True,False}.
CountIf just takes in any range and in this case can count the number of True values.
So we can wrap CountIf around the values produced by ArrayFormula like this:
=CountIf(ArrayFormula(B2:B6<>""),TRUE)
Further Reading
The other solutions in this thread are either overly complex, or fail in particular edge cases that I've enumerated in this test sheet:
Google Spreadsheet - CountA Test - Demo
For why CountA works the wonky way it does, see my answer here
For me, none of the answers worked for ranges that include both virgin cells and cells that are empty based on a formula (e.g. =IF(1=2;"";""))
What solved it for me is this:
=COUNTA(FILTER(range, range <> ""))
It works for me:
=SUMPRODUCT(NOT(ISBLANK(F2:F)))
Count of all non-empty cells from F2 to the end of the column
Solved using a solution i found googling by Yogi Anand: https://productforums.google.com/d/msg/docs/3qsR2m-1Xx8/sSU6Z6NYLOcJ
The example below counts the number of non-empty rows in the range A3:C, remember to update both ranges in the formula with your range of interest.
=ArrayFormula(SUM(SIGN(MMULT(LEN(A3:C), TRANSPOSE(SIGN(COLUMN(A3:C)))))))
Also make sure to avoid circular dependencies, it will happen if you for example count the number of non-empty rows in A:C and place this formula in the A or C column.
Given the range A:A, Id suggest:
=COUNTA(A:A)-(COUNTIF(A:A,"*")-COUNTIF(A:A,"?*"))
The problem is COUNTA over-counts by exactly the number of cells with zero length strings "".
The solution is to find a count of exactly these cells. This can be found by looking for all text cells and subtracting all text cells with at least one character
COUNTA(A:A): cells with value, including "" but excluding truly empty cells
COUNTIF(A:A,"*"): cells recognized as text, including "" but excluding truly blank cells
COUNTIF(A:A,"?*"): cells recognized as text with at least one character
This means that the value COUNTIF(A:A,"*")-COUNTIF(A:A,"?*") should be the number of text cells minus the number of text cells that have at least one character i.e. the count of cells containing exactly ""
A simpler solution that works for me:
=COUNTIFS(A:A;"<>"&"")
It counts both numbers, strings, dates, etc that are not empty
As far as I can see, most of the solutions here count the number of non empty cells, and not the number of rows with non empty cell inside.
One possible solution for the range B3:E29 is for example
=SUM(ArrayFormula(IF(B3:B29&C3:C29&D3:D29&E3:E29="";0;1)))
Here ArrayFormula(IF(B3:B29&C3:C29&D3:D29&E3:E29="";0;1)) returns a column of 0 (if the row is empty) and 1 (else).
Another one is given in consideRatio's answer.
You can define a custom function using Apps Script (Tools > Script editor) called for example numNonEmptyRows :
function numNonEmptyRows(range) {
Logger.log("inside");
Logger.log(range);
if (range && range.constructor === Array) {
return range.map(function(a){return a.join('')}).filter(Boolean).length
}
else {
return range ? 1 : 0;
}
}
And then use it in a cell like this =numNonEmptyRows(A23:C25) to count the number of non empty rows in the range A23:C25;
In Google Sheets, to count the number of rows which contain at least one non-empty cell within a two-dimensional range:
=ARRAYFORMULA(
SUM(
N(
MMULT(
N(A1:C5<>""),
TRANSPOSE(COLUMN(A1:C5)^0)
)
>0
)
)
)
Where A1:C5 is the range you're checking for non-empty rows.
The formula comes from, and is explained in the following article from EXCELXOR - https://excelxor.com/2015/03/30/counting-rows-where-at-least-one-condition-is-met/
A very flexible way to do that kind of things is using ARRAYFORMULA.
As an example imagine you want to count non empty strings (text fields) you can use this code:
=ARRAYFORMULA(SUM(IF(Len(B3:B14)>0, 1, 0)))
What happens here is that "ArrayFormula" let you operate over a set of values. Using the SUM function you indicates "ArrayFormula" to sum any value of the set. The "If" clause is only used to check "empty" or "not empty", 1 for not empty and 0 otherwise. "Len" returns the length of the different text fields, there is where you define the set (range) you want to check. Finally "ArrayFormula" will sum 1 for each field inside the set(range) in which "len" returns more than 0.
If you want to check any other condition, just modify the first argument of the IF clause.
Make another column that determines if the referenced cell is blank using the function "CountBlank". Then use count on the values created in the new "CountBlank" column.
What I want is to easily multiply a number by another number for each column and add them up at the end in Google Sheets. For example:
User | Points 1 | Points 2 | Points 3 | Total
| 5 | 1 | 4 |
-----+----------+----------+----------+------
Jane | 2 | 3 | 0 | 13 (2*5 + 3*1 + 0*4)
John | 1 | 11 | 4 | 32 (1*5 + 11*1 + 4*4)
So it's easy enough to make this formula for the total:
= B3*$B$2 + C3*$C$2 + D3*$D$2
The problem is I frequently need to insert additional columns or even remove some columns. So then I have to mess with all the formulas. It's a pain... we have many spreadsheets with these formulas. I wish there was a formula like SUM(B3:D3) where I could just specify a range. Is there anything like MULTIPLY_AND_SUM(B2:D2, B3:D3) that would do this? Then I could insert columns in the middle and the range would still work.
There is a built in function in Google Sheets that does exactly what you are looking for: SUMPRODUCT.
In your example the formula would be:
=sumproduct(B$2:D$2,B3:D3)
Click here for more information about this function.
You can accomplish that without requiring a special-purpose function.
In E3, try this (and copy it to the rest of your rows):
=sum(arrayformula(B3:D3*B$2:D$2))
You can read about arrayformula here.
As long as you introduce new columns between B and D, this formula will automatically adjust. If you add new columns outside of that range, you'll need to edit (and cut & paste).
On it's own, arrayformula(B3:D3*B$2:D$2) operates over each value in B3:D3 in turn, multiplying it by the corresponding value in B$2:D$2. (Note the use of absolute references to 'lock down' to row 2.) The result in this case is three values, [10,3,0], arranged horizontally in three rows because that matches the dimensions of the ranges.
The enveloping sum() function adds up the values of the array produced by arrayformula, which is 13 in this case.
As you copy that formula to other rows, the relative range references get updated for the new row.