How to simplify multiple COUNTIFS in excel with non-consecutive ranges - excel

I have a spreadsheet...
A you can see, the cell F2 has a formula with multiple COUNTSIF, basicly checks the cells F14, F33, F62 y there is a Pass there, and if there is one will give you a % completion. My question is that I have to add around 20-30 COUNTIFS to that formula, is there a way to simplify it.
=(COUNTIF(F14,"Pass")+COUNTIF(F33,"Pass")+COUNTIF(F62,"Pass")+COUNTIF(F75,"Pass")+COUNTIF(F88,"Pass")+COUNTIF(F105,"Pass"))/(COUNTIFS(F14,"<>na")+COUNTIFS(F33,"<>na")+COUNTIFS(F62,"<>na")++COUNTIFS(F75,"<>na")++COUNTIFS(F88,"<>na")+COUNTIFS(F105,"<>na"))
This is not the final formula, still missing around 20 entries. If you're wondering why not do a simple F15:FXX, because i just need the cells that have a test case name, like F14, F33, etc.

For the first part of your formula, you can use the INDEX function to return a non-contiguous set of values, which you can test.
For example, the equivalent for the first part would be:
=SUM(N(INDEX($F:$F,IF(1,N({14,33,62,75,88,105})))="Pass"))
The IF(1,N({…})) part is how you specify which cells (rows) in Column F to return.
Without knowing more about your data, not sure about handling the percentage issue.
Your posted formula would not calculate a percentage, as it is only dividing the SUM by whether or not F14<>"na" is true, and then adding one for the <>"na" factor for the rest
In earlier versions of Excel, you may need to confirm this array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.
If you want to return the percent "pass" in your list of cells, merely divide the SUM by the number of cells. You can either hard-code that number, or compute it with something like:
COLUMNS({14,33,62,75,88,105})
Or all together:
=SUM(N(INDEX($F:$F,IF(1,N({14,33,62,75,88,105})))="Pass"))/6
or
=SUM(N(INDEX($F:$F,IF(1,N({14,33,62,75,88,105})))="Pass"))/COLUMNS({14,33,62,75,88,105})

Related

Excel formula to count multiple possible combinations in single cell

Newbie-ish with Excel here. I'm trying to keep things simple for long term ease of use since most at my job don't know much of anything with Excel or anything with VBA.
I'm looking to have a formula count cells containing up to 4 different codes (TRM2-TRM5) out of 32 possible codes. However, the cell these combinations are entered in is not required to be in any specific order.
Such as:
B1 (TRM2, R2, TRM3)
B2 (TRM2, PN1, DC5, TRM4)
B3 (PN1, IPA5c, HW2, TRM5)
B4 (PN1, HW2, R2)
The desired result of the formula is a count of 3
I don't need to count the individual number of times the TRM codes appear. Just the number of cells they appear in a range (such as B1:B99).
I've tried COUNTIFS but quickly discovered I'd have to have a COUNTIFS for each possible combination of the 4 codes.
So far the simplest way is to use multiple instances of conditional formatting that highlights the cells that contain one of the four codes and do a visual count. All the examples I've read don't have multiple values in one cell so I'm not sure how to tackle it.
For those that are curious, the purpose is error reporting for issues missed in an audit.
Thanks for the help!
Given your example, you can do this with a helper column.
Either hard code an array constant with the codes to find, or enter them in separate cells someplace. I did the latter and named that range theCodes.
Use this array formula in the helper column:
C1: =MIN(FIND(theCodes,B1&CONCAT(theCodes)))<LEN(B1)
and fill down as far as needed
This will return TRUE or FALSE depending on whether any of the codes are present in the cell.
Then, a simple COUNTIF will count all the TRUE's
D1: =COUNTIF($C:$C,TRUE)
NOTE: To enter/confirm an array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.

How to define a range, using an Excel formula

In order to do some calculations on averages and differences of values in columns, I've defined a name, based on a range, but it seems to be completely going berserk:
I have a cell (D13), defined as Header_First _Answer, which contains the title of the column, and I have a value (currently being 69), which contains the number of entries, called Total_Count.
I've defined the entries of that column as another name: "All_First_Answered_Dates", defined as =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (start by the first entry under Header_First_Answer, take up to 69 entries, and define a range out of this).
In cell G5, I'm using that name in order to do some calculations (calculating averages), but this seems not to work (there is a #Value error).
After second comment from Rory: G5 formula and first formula evaluation result:
Formula:
=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)
First evaluation result:
=AVERAGE(IF(ISBLANK(#Value!);TODAY();All_First_Answered_Dates) - All_Start_Dates)
Hence, my conclusion:
After some checking I've found out that this is due to the name "All_First_Answered_Dates", which seems to be interpreted one time too many (or how do I explain this):
In different cells, I've entered the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (which is exactly the meaning of "All_First_Answered_Dates"), and every time, using the Evaluate Formula feature, I see that the last but one result is correct: $D$14:$D$82. However, after that, another evaluation is done, turning this value into 43283 (in case the formula is entered in "J14"), 43300 (in case the formula is entered in "J15"), ..., and in case I enter this formula in a cell with row number lower than 14, I have the error value #Value (which explains the wrong result in cell G5).
If I simply put the formula =$D$14:$D$82 in any of the mentioned cells, then the content of some cells in column D are shown (which are dates, not values like 43283 or 43300).
It appears that declaring a range as =x:y, where x and y are formula results, is not working.
Does anybody know how I can define a range as a formula, which I can then use in order to define in a name?
I can imagine my explanation being quite complicated without an image, hence the attached screenshot. In there:
In cell J13, there is the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0).
In cell J14, there is the same formula.
In cell K14, there is the formula =$D$14:$D$82.
For completion purposes, hereby a screenshot of the name manager, containing both mentioned names (the ones, selected in the name manager):
Edit after first comment:
The idea behind the range is the following:
1. Take the first row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;1;0)
2. Take the Total_Count's row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;Total_Count;0)
3. Define a range, based on those two cells, by putting a semicolon between them.
I was not aware of the height and width features of the Offset() worksheet function. I've implemented them, which makes the formulas much easier.
Unfortunately the problem still persists.
Thanks in advance
Dominique
I've just found the answer of what was going wrong:
The formula was meant to be an array formula. Something went wrong and while trying to debug, I accidently re-formatted the formula into a normal formula (I must have pressed "ENTER" instead of "Ctrl" + "Shift" + "ENTER") at some point.
I have re-applied array formula (using "Ctrl" + "Shift" + "ENTER"), getting a formula like:
{=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)}
(mind the braces {, })
Now everything is working fine.

Comparing comma separated numbers in cells

I am trying to compare the numbers in the Reachability Set column with the numbers in the same row of the Antecedent Set column and return the common values in the corresponding cells of the Intersection Set column.
Screenshot:
In Excel 2016 (but NOT Excel 2013), you can use the following array-entered formula.
=TEXTJOIN(",",TRUE,IFERROR(1/(1/(ISNUMBER(FIND(","&TRIM(MID(SUBSTITUTE(B2,",",REPT(" ",99)),seq_99,99))&",",","&A2&","))))*TRIM(MID(SUBSTITUTE(B2,",",REPT(" ",99)),seq_99,99)),""))
seq_99 is a Named Formula
Refers to: =IF(ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))=1,1,(ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))-1)*99)
To enter an array formula, after entering the formula in the cell, confirm by holding down ctrl + shift while hitting enter. If you do it correctly, Excel will place braces {...} around the formula.
Although you would think a VBA solution is required, it is actually quite simple to do this with formulae, provided you use a lot of helper columns. These can, of course, be hidden.
All you need is a number of columns equivalent to the maximum of the numerals in the sets, after each of the original columns of your table. For the example supplied, this would be 17 columns.
Here is a screenshot of the new table with the helper columns unhidden:
The follow formulae are entered into the top left cell of each coloured region and filled/copy-pasted/ctrl-entered into the rest of the cells.
Red Cells (entered into B2):
=IF(ISERROR(FIND(","&B$1&",",","&$A2&",")),0,1)
Green Cells (entered into T2):
=IF(ISERROR(FIND(","&T$1&",",","&$S2&",")),0,1)
Blue Cells (entered into AL2):
=IF(B2*T2,AL$1&",","")&AM2
And finally, the result entered into cell AK:
=LEFT(AL2,LEN(AL2)-1)
The formulae work by ensuring that all the numbers in the sets have a preceding, and trailing, comma so that they can be uniquely searched for.
Then it is a simple matter of constructing a grid for the sets where a 1 means the number exists in the set a 0 means it doesn't. Multiplying these two grids together results in the "intersection set".
Then it is a simple matter of reconstituting the result strings.
Caveat:
This solution won't work correctly if there are any spaces in the "Set" data. To overcome this you need to use the SUBSTITUTE() function.

COUNTIFS with unique values Excel

I am trying to produce a count of the number of times different strings come up in an Excel table. An example table, currently in SHEET1, would be this:
I have another table in another spreadsheet where I want to indicate, for each letter on the left in Table 1, how many entries for "za", "zc" or "zd" come up on the right. However, I would only like to only consider one entry of each.
The end result, on row B of SHEET2, would have to be something like this:
At the moment I am using a combination of SUM and COUNTIFS to do the job.
More specifically, applied to the example, I am using the following formula:
=SUM(COUNTIFS(Sheet1!A1:A18,Sheet2!$A1,Sheet1!B1:B18,{"za","zc","zd"}))
The formula is doing some of what is intended. However, it is not counting each entry just one time. Instead, its is counting, for each letter on the left, every entry of "za","zc" or "zd". The table that the formula is returning is as follows:
How can I change the formula so that it does what I intend?
Thank you.
My initial thought would be:
=SUM(MIN (1,COUNTIFS(Sheet1!A1:A18,Sheet2!$A1,Sheet1!B1:B18,{"za","zc","zd"}))
but I’m not where I can test if the MIN will apply properly to the COUNTIFS array of results. ;-)
EDITED: The MIN function is taking minimum of 1 or all of the items in the COUNTIFS array, rather than minimum of 1 and each item in the COUNTIFS array, which is what I was afraid of. Using
=MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"za"),1)+MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"zc"),1)+MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"zd"),1)
will gain the desired results. It is a little clunky, but simpler than an array formula. If you want an array formula, you can use:
=SUM(FREQUENCY(IFERROR(MATCH({"za","zc","zd"},(IF(Sheet1!$A$1:$A$18=$A5,Sheet1!$B$1:$B$18)),0),""),IFERROR(MATCH({"za","zc","zd"},(IF(Sheet1!$A$1:$A$18=$A5,Sheet1!$B$1:$B$18)),0),"")))
This uses the FREQUENCY function to take a set of values and see how many items in another set of values fall within each of the data ranges. Since you need text instead of numbers, we use the MATCH function to find out the first time the value occurs in your list, returning "" with the IFERROR function if it doesn't. (We only need the first occurrence since you don't want to know how many occurrences there are). Since it is text, we use the same input for both arguments for FREQUENCY.
Therefore, if you need to change the values you are looking for or the ranges in which you are searching, make sure to change both! Alternately, you could list the values out somewhere, say in F1:F3, and make a named range for this, another one for A1:A18, and another for B1:B18. Your formula would then look something like this:
=SUM(FREQUENCY(IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),""),IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),"")))
Then you need only change your named range definitions and your formulas would update. :-)
NOTE: Since this is an array formula, you must close out of the cell by pressing CTRL+SHIFT+ENTER rather than only ENTER. When you look at the formula bar, you should see
{=SUM(FREQUENCY(IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),""),IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),"")))}
It does NOT work to enter the curly braces yourself. ;-)
You can use this formula at B1 and fill down:
B1:
=SUMPRODUCT(((Sheet1!$A$1:$A$18=A1)*(Sheet1!$B$1:$B$18= {"za","zc","zd"}))/
COUNTIFS(Sheet1!$A$1:$A$18,Sheet1!$A$1:$A$18,Sheet1!$B$1:$B$18,Sheet1!$B$1:$B$18))

How do I sum multiple "IF" statements without "Sumifs"

I have to put together a weekly reporting system in Excel. I need to report on the month to dale sales results and the completed week (Fri-Thu). This is collected from multiple sales agents in sales documents stored in Sharepoint.
For this, I've used "SUMIFS" to collect the data, the following way:
=SUMIFS('SHAREPOINTREF/FILE.xlsm'!SalesResults[One off],'SHAREPOINTREF/FILE.xlsm'!SalesResults[Date],">="&B7,'SHAREPOINTREF/FILE.xlsm'!SalesResults[Date],"<="&C7)
(B7 is a cell reference which determines the start date of the week, with C7 being the end of the week)
The trouble with SUMIFS, as well as SUMIF, COUNTBLANK, COUNTIF and COUNTIFS, is that they don't work when the sourcing document is closed. Microsoft has a workaround here: https://support.microsoft.com/kb/260415?wa=wsignin1.0
I can't seem to figure out how to adapt the workaround methodology recommended to apply not just to a simple IF statement, but to multiples. I assume I would need to use an "AND" statement, but I keep getting errors when I'm trying.
I have about half a dozen different calculations to make, but I am pretty confident if I can solve this one, the others should start to gel a bit better.
Try this:
=SUM(IF('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]>=B7,IF('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]<=C7,'SHAREPOINTREF/FILE.xlsm'!SalesResults[One off])))
Entered using Ctrl+Shift+Enter.
Non-Array formula equivalent:
=SUMPRODUCT(--('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]>=B7),--('SHAREPOINTREF/FILE.xlsm'!SalesResults[Date]<=C7),'SHAREPOINTREF/FILE.xlsm'!SalesResults[One off])
But both seems to return #REF! when source WB is closed even though the link provided in the question claims otherwise.
Edit1:
After more digging, above will work but you need to use a Normal Range and not a Table Range.
The only problem is, you loose the advantage of Table's Dynamic Data Range.
So something like this will work even if the source is closed:
=SUMPRODUCT(--('SHAREPOINTREF/[FILE.xlsm]Sheet1'!$A$2:$A$11>=B7),--('SHAREPOINTREF/[FILE.xlsm]Sheet1'!$A$2:$A$11<=C7),'SHAREPOINTREF/[FILE.xlsm]Sheet1'!$B$2:$B$11)
The recommended solution is to use array formulas. Those are a special type of formula that, when typed, must be activated by pressing Ctrl + Shift + Enter in the formula bar. Such a function works by applying a function that would normally accept a single cell (such as IF() ) to a range. You will need to wrap the result in an aggregating formula such as SUM() or COUNT(). Here's an example:
=SUM(IF($A$1:$A$10="Apple", $B$1:$B$10, 0))
This formula would check each cell from A1 to A10 and compare it to "Apple", if it is true it will return the corresponding row from $B$1:$B$10. The result would be an array of values of column B where column A is "Apples" with zeros where it is not. The surrounding SUM() aggregates the array and gives the equivalent of SUMIF().
As I mentioned, you would need to enter Ctrl + Shift + Enter after typing the formula for it to work as an array formula. Otherwise, it will work as a regular formula.

Resources