CountIf and Subtotal - excel

I have a series of data columnar that I am wanting to use a countif for visible cells only that have the value 1. I can do either formula with no problem, CountIF, or SubTotal for visible cells, however when I try to combin them I get lost. Here is an example of my formula segments.
=CountIf(I5:I6500,1)
=SubTotal(3,I5:I6000)
How do I combine the two formulas to have a single formula that counts all instances of the number 1 in a column while not counting hidden cells due to filtering???

Desert Spider,
This worked for me:
=SUMPRODUCT(--(I5:I6000=(C12)),SUBTOTAL(3,OFFSET(I5,ROW(I5:I6000)-ROW(I5),0)))
OR (the above uses another cell value to determine your query, the below uses your user input (X))
=SUMPRODUCT(--(I5:I6000="X"),SUBTOTAL(3,OFFSET(I5,ROW(I5:I6000)-ROW(I5),0)))
Credit to:
pgc01
http://www.mrexcel.com/forum/excel-questions/600223-subtotal-countif.html#post2971937

Filter on ColumnI (as well) to select 1 and the count should appear at the bottom left of your screen (just to the right of Ready, so no formula may be needed.

Related

Count cells bigger than 0, IF empty skip cell

I'm having a problem writing my formula that should count all selected cells that contain a number bigger than 0 and skip the cells that are completely empty, even when the cell is selected. Excel gives me an error that I selected cells that not contain a number. How can I skip them?
This is my formula:
=COUNTIFS(C8:C12;E8:E12;G8:G12;I8:I12;K8:K12;">0")
I'm thinking you using the COUNTIFS() formula wrong, after each range, there is a criteria. You can't have multiple ranges like that to look through. For more information look here or here.
In your case you are dealing with a non continues range, and one way to deal with that would be this
So the formula would translate to:
=SUM(COUNTIF(INDIRECT({"C8:C12","E8:E12","G8:G12","I8:I12","K8:K12"}),">0"))
Another formula you could try is:
=INDEX(FREQUENCY((C8:C12,E8:E12,G8:G12,I8:I12,K8:K12),0),2)
And looking at your data, it seems as though the rest of the columns contain text (not sure, they may be dates). In case they are text values:
=SUMPRODUCT((ISNUMBER(C8:K12))*(C8:K12>0))
If they are actually dates (assuming from 2018), then you could try:
=SUMPRODUCT((YEAR(C8:K12)<2018)*(C8:K12>0))
I'm assuming this is what you looking for, instead of a VBA based solution due to the tags provided and your formula.
You could also do it in this particular case by skipping the columns that you don't want:
=SUMPRODUCT((C8:I12>0)*ISEVEN(COLUMN(C8:I12)-COLUMN(C8)))
what will be happen if you use the below formula? to you receive an error?
=COUNTIF(C8:C12,">0")+COUNTIF(E8:E12,">0")+COUNTIF(G8:G12,">0")+COUNTIF(I8:I12,">0")+COUNTIF(K8:K12,">0")
Try this
Requirement cannot be done in single formula,
combining 2 or more formula will help fixing the formula.
formula
=COUNTA(B2:B9,D2:D9) -- Count all the non blank cell's
=COUNTIF(B2:B9,"=0")+COUNTIF(D2:D9,"=0") -- Count all the cells will value as 0
Subtract both which will give the output you are looking for
Combined formula
=COUNTA(B2:B9,D2:D9)-(COUNTIF(B2:B9,"=0")+COUNTIF(D2:D9,"=0"))

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.

How to set the background of three cells based off of the value in one other cell, relatively?

I'm trying to make a formula that will color code three cells that are directly above/below each other. The color coding depends on the sum of three other cells that are directly above/below each other, and directly across from the cells to be colored.
This part is easy. The rule is:
Forumula: =SUM(H5:H7)>30
And it applies to:
$E$5:$E$7
However, the issue is that when I copy the cells that are being colored (E's) to three more cells below them for the next batch, the relative formula does not work as expected. It applies the formula on H6:H8 (+1) instead of H8:H10 (+3).
Is there a way to get the relativeformula to work as expected? I hope this was clear enough. I know it's hard to visual a spreadsheet, but ultimately I need the relative forumla to add +3 instead of +1 when it is copied.
Problem:
If I correctly understand, what you are trying to achieve is to have the range E5:E7 formatted strictly based upon H5:H7, then the next three-cell range - E8:E10 - based upon H8:H10 and so on. You can do this by implementing the below solution:
Solution:
Step 1: Setup Columns as Below
Step 2: Implement Conditional Formatting as Below
Explanation:
I have recreated your issue and I see your problem; it was not that obvious until I played around with changing values of different cells in Column H.
Apparently, this has to do with how Excel interprets your instructions (formula) supplied under conditional formatting. To understand this let's first focus on the behavior of cells E5, E6 and E7 as a function of values in Column H.
With the formula =SUM(H5:H7)>30 did you notice that:
E5 format depends upon =SUM(H5:H7),
E6 format depends upon =SUM(H6:H8), and
E7 format depends upon =SUM(H7:H9) and
when you copy the range E5:E7 three cells down into E8:E10, the expected behavior is:
E8 format depends upon =SUM(H8:H10),
E9 format depends upon =SUM(H9:H11), and
E10 format depends upon =SUM(H10:H12)
And this is exactly how the range E8:E10 will behave once the above solution is applied.
A partial answer to your question has to do with your relative formula - =SUM(H5:H7) - under conditional formatting. Using this formula causes $E$5 to use =SUM(H5:H7) to determine its formatting, $E$6 to use =SUM(H6:H8) to determine its formatting, and so on. This ultimately leads to issues with the conditional formatting even before you begin copying the cells down.
EDIT: (piggy-backing off #Bharat Anand's answer)
#Bharat Anand's answer appears to be the best way to accomplish this question.
#Thisisstackoverflow requested clarification (under the accepted answer) and I'm hoping my screenshot below will help.
I set my worksheet up in what I believe is the exact same manner as #Bharat Anand, and it seems that the column letters may have been off. Setting mine up like this made it work correctly.
EDIT: (clarification for future visitors)
I really liked #Bharat Anand's solution, so I wanted to explain how it works (using the images/formulas in the solution as reference):
The calculation in Column I is setup to return a number that will only appear three times, in succession, in Column I; in this way it kind of behaves like a unique identifier, allowing other formulas to reference these values for calculation purposes.
Three times is key for the original poster because they were looking for a range of three cells to be formatted based on a sum of three cells. For example, the formula in Column I can be modified to
=ROUNDDOWN((ROW()-b)/a,0)
where:
a is your desired number of cells to format/sum, and
b is equal to a - 1.
Using the formula in J5 as an example, this SUMIF formula uses I3:I7, which includes two (or b, as setup in my explanation above) rows above and two (b) rows below to decide if I5 equals any of the values found in I3:I7. It's important to include the two rows above and two rows below so that the range overlaps the same three cells to meet the requested requirements.
When I5 finds a match, the formula looks to Column H to sum those rows in H3:H7 where I3:I7 equals I5. In this example, J5, J6, and J7 will each equal 32.
Using the simple conditional formatting formula that was setup, we know that cells in Column E should be highlighted when the corresponding row in Column H is greater than 30. According to the original question, this should be done in ranges that are three (a) rows tall. We already handled for that, so all that was left was to make sure the conditional formatting spanned the data area in Column E.
I'm hoping I don't confuse and/offend anyone with this explanation, but it's how I understand it. I like the proposed solution and explaining it to myself again helps me solidify how it works.

When I highlight and 'f9' the components of an array formula it will compute the answer correctly, but doesn't work normally

So I have replicated the error with dummy data here.
I am trying to populate C2:C5 with the totals from the value column in the rawdata table that correspond to the values in B2:B4 multiplied by the looked up values in type table.
when I highlight the respective arrays in the Sumproduct formula and leave them as values they are calculating correctly, but for some reason the formula doesn't work as is.
=SUMPRODUCT(RawData[Value],--($B2=RIGHT(RawData[Vehicle],LEN($B2))),OFFSET(Multiplier[[#Headers],[Multiplier]],MATCH(RawData[Type],Multiplier[[Type ]],0),0))
EDIT:
I have a sumproduct formula with three arrays, the first is a column full of values, the second is a list of bools and the third is a list of multipliers.
The formula is returning 0 even when all criteria are met.
I have identified that it is the third array of multipliers that is causing the problem. If I highlight that section of formula, hit F9 and convert it to values, the whole thing calculates correctly. but when it is left as a formula it is returning 0.
Just in case anyone in the future has a similar issue, I think it's the offset part of the function.
=SUMPRODUCT(RawData[Value],--($B2=RIGHT(RawData[Vehicle],LEN($B2))),OFFSET(Multiplier[[#Headers],[Multiplier]],MATCH(RawData[Type],Multiplier[[Type ]],0),0))
You can in this situation use sumif instead:
=SUMPRODUCT(RawData[Value],--($B2=RIGHT(RawData[Vehicle],LEN($B2))),SUMIF(Multiplier[[Type ]],RawData[Type],Multiplier[Multiplier]))
credit to /u/rnelsonee
/r/excel Thread

How can I add values only if "x" is present?

I'm working on adding a collection of board games to our library.
I have a spreadsheet that lists more games than I intend to buy, but have them there to investigate. I have the prices for a couple of websites listed beside each game.
The problem is that I want a sum that doesn't include every game on the list. Instead, I want to add a column at the front that if I put an "X" indicating this is a game to get, then I want it to add the value for that. Only the values for rows that start with an "X" in column A will in added together, instead of everything.
I was hoping to do this with a formula instead of just choosing a basic =SUM formula and selecting only a few cells at a time. I assume a =SUMIF might be the answer, but I have yet to figure out how to get this to work.
Please try:
=SUMIF(A:A,"x",B:B)
where B:B is the column with the values. I suspect your difficulty may have been that when using text as the 'trigger' it needs to be in double inverted commas.
Or you might sort by ColumnA and just use =SUM as far down as there are xs.
Or filter on ColumnA to select x and Autosum ColumnB but change the 9 to 109.
SUMIF requires at least 2 parameters, and at most 3. In your case, you will need to use 3.
If you type the formula in excel, you will see a little balloon indicating:
=SUMIF(Range, Criteria, [Sum_Range])
Range is the range where you want to apply the condition, in your case, A:A.
Criteria is the condition applied to the range, in your case "x".
[Sum_Range] is the range to sum, after applying the condition.
The above will sum all the cells in the range [Sum_Range], for which the cells of Range satisfies the condition Criteria.
Translating that into an actual formula, you get pnut's formula:
=SUMIF(A:A,"x",B:B)
The above will sum all the cells in the range B:B, for which the cells of A:A satisfies the condition x (SUMIF considers the criterion as being 'equal' so it will sum only when they are equal to the criteria).
As an extra, you can change the condition to mean 'not equal' by using something like this: =SUMIF(A:A,"<>x",B:B) (the <> means not equal to in Excel).

Resources