COUNTIF filtered data, Criteria >0 - excel-formula

How can I countif filtered data, criteria >0. I have been using this formula and it returns me 0. Does the formula need to be tweeked a little? Or could any of you please provide me a different solution.
=SUMPRODUCT(BV9:BV784>0,SUBTOTAL(3,OFFSET(BV9:BV784,ROW(BV9:BV784)-MIN(ROW(BV9:BV784)),,1)))

SUMPRODUCT does not work with booleans.
The only problem I could see in your formula is that
BV9:BV784 > 0
generates a Boolean array, while you want a numeric zero-or-one array. You can force the conversion of the boolean array into a zero-or-one array using (among other possible ways) the -- trick:
=SUMPRODUCT(--(BV9:BV784>0),SUBTOTAL(3,OFFSET(BV9:BV784,ROW(BV9:BV784)-MIN(ROW(BV9:BV784)),,1)))
' ^^^^^^^^^^^^^^^^

Related

SUMPRODUCT ( 1/COUNTIF( range, criteria)). WHY DOES THIS WORK

I need to count how many different values are in a range. I got the answer by using SUMPRODUCT(1/COUNTIF(A2:A37,A2:37)), however, I don't understand the formula, can someone please help me explain?
If I do the COUNTIF separately, the result is 0? How does SUMPRODUCT(1/COUNTIF) help? Also, inside the COUNTIF, the range and criteria are the same, what does this mean? I understand that the range is where we look for, and the criteria is for what criteria, but if the criteria is the entire range, how are we specifying what we're looking for here? How does this translate/work?
Here my sample input:
enter image description here
Just extend some of the comments provided in your question for a better understanding. Here: Excel dynamic arrays, functions and formulas you can find a detail explanation about dynamic arrays and implicit interception and how it has changed through Excel evolution.
SUMPRODUCT (array1, [array2], ...) can be used with a single argument, in such case it sums all elements in array1, i.e. similar to SUM function (Excel SUMPRODUCT Function). For example: SUMPRODUCT({1;2;3}) = 6.
Note: Multiplication is the default operation of SUMPRODUCT, but you can use others (check this link) replacing the , with the corresponding operation. For example: SUMPRODUCT({1;2;3}/({1;2;3}))=3 (acts as COUNT), i.e. 1/1+2/2+3/3 but SUMPRODUCT({1;2;3},{1;2;3})=14, i.e. 1*1+2*2+3*3.
COUNTIF(range, criteria) the first argument has to be a range, but the second argument can be a number, expression, cell reference, or text string that determines which cells will be counted, but it also can be a range or an array (Excel COUNTIF function). If that is the case, COUNTIF is invoked for each element of criteria and returns an array of the same size and shape as criteria. For example if the following range A1:A4 has the following values:
|1|
|2|
|1|
|1|
the following expressions will return:
COUNTIF(A1:A4, 1) = 3
COUNTIF(A1:A4, A1:A2) = {3;1} i.e. 2x1 array
COUNTIF(A1:A4, {1;2}) = {3;1}
COUNTIF(A1:A4, {1,2}) = {3,1} i.e. 1x2 array
and for a two dimensional criteria {1,2;0,1} a 2x2 array:
=COUNTIF(A1:A4, {1,2;0,1}) = ={3,1;0,3} i.e. 2x2 array
Note: Remember you can not invoke the function with the first input argument as an array, for example: COUNTIF({1;2;1;1}, 1) returns an error. It has to be a range.
so we can count how many times each element of the first input argument is repeated like this:
COUNTIF(A1:A4,A1:A4) = {3;1;3;3} i.e. 4x1 array
Now back to SUMPRODUCT (remember with a single argument it is just the sum of the elements):
SUMPRODUCT(COUNTIF(A1:A4,A1:A4))
= SUMPRODUCT({3;1;3;3})
= 10
i.e. sum of occurrences of each element of A1:A4
and finally:
SUMPRODUCT(1/COUNTIF(A1:A4,A1:A4))
= SUMPRODUCT({1/3;1/1;1/3;1/3})
= 3*(1/3) + 1
= 2
which results in total total number of unique elements in A1:A4. As #Harun24hr pointed out, it can be achieved in Microsoft 365 with: COUNTA(UNIQUE(A1:A4) or also COUNT(UNIQUE(A1:A4) since in the example of this answer A1:A4 are numbers, but in the sample of your question (letters) you have to use: COUNTA.

SUMIFS Is Blank OR Other Condition

I am trying to sum the values in the B2:B4 range using the SUMIFS function if the dates in the C2:C4 range are either blank or after the date in cell C1.
I can add the values in B if cells in C2:C4 are either blank or if the dates are after C1, in separate formulae, but I cannot seem to combine those conditions into one formula with an OR condition.
=SUMIFS(B2:B4,C2:C4,"") + SUMIFS(B2:B4,C2:C4,">"&C1)
The formula that I am working on is actually much longer and complicated so I want to combine these conditions into one formula or condition inside a SUMIFS if possible.
I have looked for hours but cannot seem to find what I am looking for. Solutions I have found thus far test for blank and a text value or if greater than 0, but not a comparison of non-text non-zero values such as dates. Does anyone know of the solution?
I think we can not put the "or" condition in one criteria range with cell reference.
You can use the SUMIFS formula but you have to hard code the criteria value of date.
Pass the "or" conditions in { },this will return the value for both "or" conditions than use SUM function to get the total value.
SUM(SUMIFS(B2:B4,C2:C4,{">15-05-2021",""}))
Use of SUMPRODUCT function will be a better option in given condition
SUMPRODUCT(--(C2:C4>C1)+(C2:C4=""),B2:B4)

COUNTIFS or SUMPRODUCT : Count of non-blank values in range with index criteria matching a string

I am trying to count how many cells have a date value in a range, where the row index matches a given criteria; a string value matching a corresponding value in another column on the same row.
Basically a COUNTIF formula, where the count range is different from the search range.
I believe I almost have the answer but it's quite right:
=SUMPRODUCT(--(tblUK[Content Type]=[#[Content Type]]),tblUK[Completed]<>"")
Edit: The data is actually two different tables, this might clarify:
=SUMPRODUCT(--(tblUK[Content Type]=tblBurndown[#[Content Type]]),tblUK[Completed]<>"")
or without Table formula jargon...
=SUMPRODUCT(--(UK!F:F="Physical",UK!E:E<>"")
I have come up with an answer using COUNTIFS after all:
=COUNTIFS(tblUK[Completed],">0",tblUK[Content Type],[#[Content Type]])
However, I don't see why SUMPRODUCT won't do the job just as well, would be good to find out why it isn't working.
Edit: I think I've cracked it... just had to do a bit more reading on SUMPRODUCT. The missing element was multiplying the boolean array (first array) by the 2nd array.
=SUMPRODUCT(--(tblUK[Content Type]=[#[Content Type]])*(tblUK[Completed]>DATEVALUE("01/01/1900")))

Excel formula -> how to change SUMPRODUCT formula to skip null cells

context is
I am using adjusted sumproduct formula to calculate weighted average.
problem is
sumproduct includes empty cells in arrays. => weighted average is calculated incorrectly.
question is
How to edit sumproduct to exclude empty cells in arrays?
alternatively
Is there another clean and neat solution?
In the sumproduct, to exclude empty cells, suppose you're using it on range A1:A100, you could do the following:
= Sumproduct((A1:A100),--(A1:A100<>""))
That second criteria will ensure that you're only looking at cells that have a value in them...
As an explanation (A1:A100<>"") will return an array of True False, where, if there is a value in the cell, it returns true, otherwise, false. Then, including the -- before it, it converts True/False to 1/0. So, in effect, you're multiplying empty cells by a zero (excluding from the formula) and non-empty cells by 1 (including them in the formula).
The --(logical statement for my array) is a very useful trick to use with SumProduct() in MANY different ways!!

Excel: VLOOKUP that returns true or false?

In Excel we have the VLOOKUP function that looks for a value in a column in a table and then returns a value from a given column in that table if it finds something. If it doesn't, it produces an error.
Is there a function that just returns true or false depending on if the value was found in a column or not?
You could wrap your VLOOKUP() in an IFERROR()
Edit: before Excel 2007, use =IF(ISERROR()...)
You still have to wrap it in an ISERROR, but you could use MATCH() instead of VLOOKUP():
Returns the relative position of an
item in an array that matches a
specified value in a specified order.
Use MATCH instead of one of the LOOKUP
functions when you need the position
of an item in a range instead of the
item itself.
Here's a complete example, assuming you're looking for the word "key" in a range of cells:
=IF(ISERROR(MATCH("key",A5:A16,FALSE)),"missing","found")
The FALSE is necessary to force an exact match, otherwise it will look for the closest value.
Just use a COUNTIF ! Much faster to write and calculate than the other suggestions.
EDIT:
Say you cell A1 should be 1 if the value of B1 is found in column C and otherwise it should be 2. How would you do that?
I would say if the value of B1 is found in column C, then A1 will be positive, otherwise it will be 0. Thats easily done with formula: =COUNTIF($C$1:$C$15,B1), which means: count the cells in range C1:C15 which are equal to B1.
You can combine COUNTIF with VLOOKUP and IF, and that's MUCH faster than using 2 lookups + ISNA. IF(COUNTIF(..)>0,LOOKUP(..),"Not found")
A bit of Googling will bring you tons of examples.
We've always used an
if(iserror(vlookup,"n/a",vlookup))
Excel 2007 introduced IfError which allows you to do the vlookup and add output in case of error, but that doesn't help you with 2003...
You can use:
=IF(ISERROR(VLOOKUP(lookup value,table array,column no,FALSE)),"FALSE","TRUE")
ISNA is the best function to use. I just did. I wanted all cells whose value was NOT in an array to conditionally format to a certain color.
=ISNA(VLOOKUP($A2,Sheet1!$A:$D,2,FALSE))

Resources