I find myself doing a lot of operations on tables where I am not sure about entry count.
I simply guess that it should be lower than 100 and just do =SUM(A1:A100). Now if I have only 2 entries, all the other rows are useless for other things.
How can I solve this problem? Maybe I can automatically detect continuous values without an empty row in between or something?
I am not about performance. If I use 100 rows for some formula just to be safe in the future but only 3 rows have values present I just wasted a lot of spreadsheet space making it harder to use and read.
EDIT
To explain what I mean by saying 'waste of space'.
I don't know how many name:value pairs I will have. Maybe 5 maybe 100. So in this case I have 3 entered but 5 empty columns. That means I have wasted 2 columns of space. When I want to be sure my calculations will handle a lot of values, I just do like =SUM(A2:A100) and leave it like that but then it's impossible to place another attributes or more values.
You can use =CAUNTA() function.
COUNTA
I'm still not convinced how one could 'waste spreadsheet space' and I would recommend using simply =SUM(A:A) in such a case.
If you must sum up to the very last cell in column A, then maybe this formula would suit you:
=SUM(A1:INDEX(A:A,MATCH(9^99,A:A)))
This formula will ignore any blanks if any and count down to the last value.
Another possible (and maybe simpler) formula is with SUMIF:
=SUMIF(A:A, "<>0")
Since blanks are considered as 0, they won't get summed, but as I said, I find it much simpler to just use SUM(A:A) since blanks are zeros anyway.
Related
I have a Row and the range is B2:B10 and the numbers are from 1 - 9. At random about 1/2 of those numbers will be placed in this Row and need the formula to tell me what numbers are missing. Of course, I can simply look and tell what they are but would like for the formula to let me know. When you ask this question on the Internet it gives the solution for Columns and not Rows. I know this involves an array, but haven't quite mastered that yet.
Thanks.
=TEXTJOIN(",",,IF(ISERROR(MATCH({1,2,3,4,5,6,7,8,9},B2:B10,0)),{1,2,3,4,5,6,7,8,9},"")) should work if a you need a list of numbers not included.
So, for large number it is hard to hardcode numbers in array. You may like this dynamic approach where you do not need to hardcode numbers rather you can just use SEQUENCE() function (if your Excel have it) to define how many numbers you want to check. Try-
=TEXTJOIN(",",TRUE,IF(ISERROR(MATCH(SEQUENCE(20),B2:B10,0)),SEQUENCE(20),""))
I'm trying to sum some values (both positive and negative) in a column, but it won't sum as there are #n/a values. Is there any way to get around this? Please see the example below:
Each city has lower areas that have income,crime & unemployment scores (either positive or negative).
My goal is to get city-wide income, crime and unemployment scores by summing lower areas' scores.
I'm using 'sumifs' in G2 as in =SUMIFS(C$2:C$10,$A$2:$A$10,$A2) and then dragging it to I10. In this toy example, there are only 10 rows, but my data have 1 million rows, so I cannot really do dragging. Any suggestions on that would also be helpful!
But, most importantly my problem is that I cannot use 'sumifs' due to the #N/A values. I want to ignore them.
Or simply replacing all the #N/A values with 0 in the 1 million rows would also be an option.
p.s. I have done some research on previous similar questions, but they seem to use different 'sumifs' formulae...
Using SUMIFS with <0 AND >0
You could use this:
=SUMIFS(C$2:C$10,$A$2:$A$10,$A2,C$2:C$10,"<0")+SUMIFS(C$2:C$10,$A$2:$A$10,$A2,C$2:C$10,">0")
It avoids zero (which makes no difference in this case).
It also avoids cells that contain values that are not numbers, such as NA, which often prevents summing (avoiding these solves your issue in this case).
If I understand it correctly, you want to get the sum of both positive and negative numbers (i.e. their existing values, not absolute values), however that is currently being prevented using your existing approach by the presence of the NA items.
If this is not correct, please advise.
USING AN INTERIM LOOKUP, THEN SUMIF WITH <0 AND >0
You could alternatively insert a lookup column, which concatenates the values to evaluate, and then use SUMIF.
For example, new column J:
=$A2&C2
(noting the $ for the A as well as the absence of $ for the C)
Then fill J1 to the right to K1 and L1
Then in M1:
=SUMIF(J$2:J$10,"<0",C$2:C$10)+SUMIF(J$2:J$10,">0",C$2:C$10)
Then fill right to N1 and O1
The potential issue with this approach is if you fill down millions of rows the spreadsheet may slow down significantly.
REPLACING NA
Replacing the NA with 0 will also work, but you may not wish to lose the distinction between "0" and "not shown in source data".
Please post your existing formula for the NA values if you would like to go down that path. They may be reworkable into something instead of NA that is meaningful and does not prevent summing.
It is often preferable when looking up data to trap for the possibility of NA and return some other more meaningful (or in this case, more sum-friendly) result.
Perhaps the easiest way is to use the "<>#N/A" criteria as in =SUMIFS(C$2:C$10,$A$2:$A$10,$A2, C$2:C$10, "<>#N/A") which will ignore NA in the sum column. You could add additional criteria for other conditions columns if they are interfering with numeric conditions checks.
Thanks: https://www.mrexcel.com/board/threads/sumifs-while-ignoring-n-a.1042338/ for the tip.
This is what I'm trying to do. There are two columns. The first one contains the drawing number of a P&ID and The other one contains the IO type. Columns B and N respectively. I want the number of DOs for the drawing number ZCPL-P2179-B1-101. I know a simple COUNTIF function works but it is inefficient since rows keep expanding and it is quite tedious to constantly reselect the ranges.
Why dont you use Simple Countif with whole column as a Range
=COUNTIFS(B:B;"B1";C:C;"C1")
Just drag this formula in the whole column, even if your data is increasing you just have to click once to drag the formula.
Later take out Unique of P&ID number and Dos to find the distinct count.
I hope this helps
I'm working on data from a population of people with allergies. Each person has a unique ExceptionID, and each allergen has a unique AllergenID (451 in total).
I have a data table with 2 columns (ExceptionID and AllergenID), where each person's allergies are listed row by row. This means that the ExceptionID column has repeated values for people with multiple allergies, and the AllergenID column has repeated values for the different people who have that allergy.
I am trying to count how many times each pair of allergies is present in this population (e.g. Allergen#107 & Allergen#108, Allergen#107 & Allergen#109,etc). To keep it simple I've created a matrix of 451 rows X 451 columns, representing every pair (twice actually because A/B and B/A are equivalent).
I somehow need to use the row name (allergenID) to lookup the ExceptionID in my data table, and count the cases where that matches the ExceptionIDs from the column name (also AllergenID). I have no problem using Vlookup or Index/Match, but I'm struggling with the correct combination of a lookup and Sumproduct or Countif formula.
Any help is greatly appreciated!
Mike
PS I'm using Excel 2016 if that changes anything.
-=UPDATE=-
So the methods suggested by Dirk and MacroMarc both worked, though I couldn't apply the latter to my full data set (17,000+ rows) because it was taking a long time.
I've since decided to turn this into a VBA macro because we now want to see the counts of triplets instead of pairs.
With the 2 columns you start with, it is as good as impossible... You would need to check every ExceptionID to have 2 different specific AllergenID. Better use a helper-table with ExceptionID as rows and AllergenID as columns (or the opposite... whatever you like). The helper table needs a formula like:
=COUNTIFS($A:$A,$D2,$B:$B,E$1)
Which then can be auto-filled. (The ranges are from my example, you need to change them to your needs).
With this helper-matrix you can easily go for your bigger matrix like this:
=COUNTIFS(E:E,1,INDEX($E:$G,,MATCH($I2,$E$1:$G$1,0)),1)
Again, you can auto-fill with this formula, but you need to change it, so it fits your needs.
Because the columns have the same ID2 (would be your AllergenID), there is no need to lookup them because E:E changes automatically with the auto-fill.
Most important part of the formulas are the $ which should not be messed up, or you can not auto-fill it.
Picture of my self-made example (formulas are from the upper left cell in each table):
If you still have any questions, just ask :)
It can be done straight from your original set-up with array formulas:
Please note that array formulas MUST be entered with Ctrl-Shift-Enter, before copying across and down:
In the example pic, I have NAMED the data ranges $A$2:$A$21 as 'People' and $B$2:$B$21 as 'Allergens' to make it a nicer set-up. You can see in the formula bar how that looks as a formula. However you could use the standard references like this in your first matrix cell:
EDIT: silly me, N function is not needed to turn the booleans into 1's and 0's, since multiplying booleans will do the trick. Below formula works...
SUM(IF(MATCH($A$2:$A$21,$A$2:$A$21,0)=ROW($A$2:$A$21)-1, NOT(ISERROR(MATCH($A$2:$A$21&$E2,$A$2:$A$21&$B$2:$B$21,0)))*NOT(ISERROR(MATCH($A$2:$A$21&F$1, $A$2:$A$21&$B$2:$B$21,0))), 0))
Then copy from F2 across and down. It can be perhaps improved in technique with sumproduct or whatever, but it's just a rough example of the technique....
I would like to have part of an excel formula be dynamic, other than a cell reference.
For instance, suppose that in column A (cells A1:A99) I have a bunch of numbers, and I want to know how many of those numbers are greater than 50.
If I wanted this calculation to be static, I could simply use one of the following:
=COUNTIF($A$1:$A$99,">50")
=SUM(IF($A$1:$A$99>50,1,0))
=SUM(($A$1:$A$99>50)*1)
I mention all three because my actual formula is hairy and a bit of a mix of the second and the third. (After all, perhaps something will work with COUNTIF but not with the others.)
Now, I want to be able to type my condition in another cell (say C1). So if I type ">50" in C1, my calculation will be as above, but if I type "<100" I will count how many entries of column A are less than 100.
Is this possible? (I am using Excel 2003 on Windows XP.)
There may be something that I'm missing.
If you give
=COUNTIF($A$1:$A$99,C1)
in any cell, and then in cell C1 you type >50 or <100
don't you get what you want?
Use INDIRECT
=INDIRECT(COUNTIF($A$1:$A$99,">50"))
is same as
=COUNTIF($A$1:$A$99,">50")
But, as you identified, the former, you can generate within the excel cells! I do it all the time, for such things.
I usually solve this by adding another column carrying the result of a complex logical expression, like
=AND(OR(C3<D3;E3>=100);A3=VLOOKUP(B3;Sheet2!$A$2:$B$212;2;FALSE))
this formula is in all rows of -say- column F - note: no IF needed here!
then I calculate a complex conditional sum across column E using =SUMIF() like
=SUMIF(F2:F57;TRUE;E2:E57)
I know that some users say "I do not want to change my design. That's ok; my argument is that I have better control over the condition, I can work on the condition seperately from summing up or other functions that rely on that condition, and I can filter records for TRUE or FALSE to look at the subsets and have a rapid overview if the formula makes sense
hope that helps Good luck MikeD