Excel Counting non blank cells - excel

I am having no luck trying to count my non blank cells in excel. I have tried multiple formulas and I keep getting inaccurate data. Here is the situation:
I am creating a Preventative Care list for my physicians (I have 4) I created a list of all their patients that have received a letter re: Prev. Care and I am inputting who needs a second letter and who has results. Some results are negative, some are positive. I have the list set up in alphabetical order on patients last name and then I have their physician initials in the other column. I want to check to see what percentage of each doctors patients have done their prev. care. I want to calculate this separately. Unfortunately, the cells are no in order. I have tried everything to my knowledge.
Help!

This will give you how many blank cells you have. You can deduct this from the total number of cells in your column, or you could use this directly to compute your percentage as (1 - x) where x is percentage of blank cells.
=COUNTBLANK(<your column>)
E.g:
=COUNTBLANK(A1:A10)

If it's not immediately obvious how to count the total number of cells in a range, this formula should help explain, answering the original question fully. It works with ranges that span more than 1 column, too.
=ROWS(range)*COLUMNS(range)-COUNTBLANK(range)

You might try something like:
=IF(LEN(A1) > 0, 1, 0)
You can then sum that column or do whatever other calculation you need.

=COUNTIF(range,"<>"&"") will count all cells that do not have a value equivalent to "", so, basically anything that is not blank.

Related

Excel countifs any random cell from given range has the same value

Not sure how to formulate my question so I'll start with an example.
I have a dataset that looks like this (the whole dataset has ~150000 rows) - highlighted some of the values for easier viewing:
What I want to do is count how many times "Johnson, Jim, 10" and "Gordon, Tom, 15" appear in the same SUBDATA set where the first column cells have the same value.
I counted how many times the respective values appear in the whole data set separately using COUNTIFS:
But what I want to do is somehow counting how many times both iterations of the given data ("Johnson, Jim, 10" and "Gordon, Tom, 15") appear IF the first column value is the same (the value should be a DATE in the format YYYYMMDD).
I don't want to give the formula a date e.g. 20221005 and see if those 2 instances appear together because I have hundreds of dates. I just want to somehow tell the formula to CHECK when it finds any of those two records if there is an instance where the DATE is the same and count it.
e.g. If "Johnson, Jim, 10" and "Gordon, Tom, 15" have their respective related A cell with the same value (20221010), count it. And see how many times this happens in the whole dataset.
I would like to know if it's possible to do this using only formulas, without using Macros.
PS: Sorry if I didn't make myself clear enough, I will answer every question you have.
Here is a long way round:
Formula in K2:
=LET(x,FILTER(A1:A12,BYROW(B1:D12,LAMBDA(a,SUM(--(MMULT(--(a=H1:J2),{1,1,1})=3))))),COUNT(UNIQUE(FILTER(x,MAP(x,LAMBDA(y,SUM(--(x=y))))=2))))
Assuming within each date group there are no duplicated values (if not the formula can be adjusted), then you can use the following formula in I3:
=LET(dates, A1:A12, values, B1:B12&C1:C12&D1:D12, lkUp, F2:F3&G2:G3&H2:H3,
REDUCE(0, UNIQUE(dates), LAMBDA(acc,ux, LET(
set, FILTER(values, dates=ux), match, IF(COUNT(XMATCH(lkUp, set))=2, 1, 0),
acc + match)))
)
and here is the output:
What it does is for each unique dates it uses concatenation to find index positions via XMATCH. If both lookup values (lkUp) are found it is counted as 1, otherwise 0. REDUCE does the total sum of all matches.

Excel Mac: If these two arguments are true then count/sum the number of unique ID#s

This is what I am trying to figure out:
IF date in cell matches dates in range
and
If name in cell matches names in range
then
count/sum the number of unique ID#s
This is the formula I have:
=IF(Data!A:A=E10,(IF(Data!D:D=D11,(IF(Data!D:D=D11,SUM(IF(FREQUENCY(Data!C:C,Data!C:C)>0,1)),"ERROR3")),"ERROR2")),"ERROR1")
It does not output the correct info. It either counts all the unique IDs or it Errors out when it should have a result.
I hope I am on the right track, thank you for any help.
Sample dataset:
Try it as,
=SUMPRODUCT(SIGN((B$2:B$10>=E2)*(B$2:B$10<=F2))/
(COUNTIFS(B$2:B$10, ">="&E2, B$2:B$10, "<="&F2, A$2:A$10, A$2:A$10)+(B$2:B$10<E2)+(B$2:B$10>F2)))
First let me say that the question was pretty confusing before you posted an image of the data, as it appears that the term "dates in range" was completely misleading. In fact you are trying to match exact dates, not "ranges of date".
FREQUENCY is useful to detect the first appearance of an item in a column, but unfortunately, this "artificial trick" is not flexible enough to be mixed easily with other criteria, and most importantly FREQUENCY is not array friendly.
There's another method to achieve you goal, which is:
=SUMPRODUCT(((Data!$A$1:$A$24=E$10)*Data!$C$1:$C$24=$D11))/
COUNTIFS(Data!$A$1:$A$24,Data!$A$1:$A$24,Data!$B$1:$B$24,Data!$B$1:$B$24,Data!$C$1:$C$24,Data!$C$1:$C$24))
You can enter this formula in E11 in your sample image and copy/paste in the whole matrix.
The denominator of the formula (the second line) generates an array that counts for each row the number of duplicates.
The numerator sets the criteria. Since each successful row will repeat as many times in the numerator and in the denominator, each matching row will be counted for a total of one.
As a result, we obtain the number of "unique rows" that match the criteria.
The formula should not use complete columns such as A:A etc, make the effort to limit it to a reasonable number of rows, say A1:A999 or so. Complex formulas involving arrays must avoid as much as possible entire columns.

Excel - Counting number of phone numbers in range

Cell A2: 5555550000
Cell A3: 5555550003
Trying to find a way to count the number of phone numbers in this range. The cheat way is:
=A3-A2+1
This would give me "4" because the first phone number actually is a value that needs to be calculated. Such is the case with a range like 5550000-5550099 which is 100 numbers, not 99.
Is there a function in excel that actually does the same thing as my cheat formula? I'm in the mood to learn something. Upon searching the internet, I didn't find anything that could help me in this case.
Thanks!
For many small and large blocks Excel can help. With the lower limit of each in ColumnA and the upper in ColumnB (a repeat of the A value where a single number 'range') then summing the two columns (say in Row12) and:
=B12-A12+COUNT(A1:B11)/2
should give the total. This is barely easier than B1-A1+1 - very similar to your approach - and then copying down and summing but may have a slight advantage in that it might be used as a template, where if the totals are in a row with high enough number there will always be empty rows available (and the result always in the same cell). The +1 in the shorter formula would not allow that, though would easily be overcome with:
=IF(A1<>0,B1-A1+1,0)

If "0" then leave the cell blank

I am trying to create a simple ledger and on the far right of the "Book" it totals any debit/credit that I input. But instead of leaving the unused rows blank, it keeps repeating the latest total to the bottom of the page.
How Can I make that cell blank if the equation equals 0?
=H15+G16-F16
is the formula I am currently using.
You can change the number format of the column to this custom format:
0;-0;;#
which will hide all 0 values.
To do this, select the column, right-click > Format Cells > Custom.
Use =IF(H15+G16-F16=0,"",H15+G16-F16)
=iferror(1/ (1/ H15+G16-F16 ), "")
this way avoids repeating the central calculation (which can often be much longer or more processor hungry than the one you have here...
enjoy
Your question is missing most of the necessary information, so I'm going to make some assumptions:
Column H is your total summation
You're putting this formula into H16
Column G is additions to your summation
Column F is deductions from your summation
You want to leave the summation cell blank if there isn't a debit or credit entered
The answer would be:
=IF(COUNTBLANK(F16:G16)<>2,H15+G16-F16,"")
COUNTBLANK tells you how many cells are unfilled or set to "".
IF lets you conditionally do one of two things based on whether the first statement is true or false. The second comma separated argument is what to do if it's true, the third comma separated argument is what to do if it's false.
<> means "not equal to".
The equation says that if the number of blank cells in the range F16:G16 (your credit and debit cells) is not 2, which means both aren't blank, then calculate the equation you provided in your question. Otherwise set the cell to blank("").
When you copy this equation to new cells in column H other than H16, it will update the row references so the proper rows for the credit and debit amounts are looked at.
CAVEAT: This equation is useful if you are just adding entries for credits and debits to the end of a list and want the running total to update automatically. You'd fill this equation down to some arbitrary long length well past the end of actual data. You wouldn't see the running total past the end of the credit/debit entries then, it would just be blank until you filled in a new credit/debit entry. If you left a blank row in your credit debit entries though, the reference to the previous total, H15, would report blank, which is treated like a 0 in this case.
An accrual ledger should note zeroes, even if that is the hyphen displayed with an Accounting style number format. However, if you want to leave the line blank when there are no values to calculate use a formula like the following,
=IF(COUNT(F16:G16), SUM(G16, INDEX(H$1:H15, MATCH(1e99, H$1:H15)), -F16), "")
That formula is a little tricky because you seem to have provided your sample formula from somewhere down into the entries of the ledger's item rows without showing any layout or sample data. The formula I provided should be able to be put into H16 and then copied or filled to other locations in column H but I offer no guarantees without seeing the layout.
If you post some sample data or a publicly available link to a screenshot showing your data layout more specific assistance could be offered. http://imgur.com/ is a good place to host a screenshot and it is likely that someone with more reputation will insert the image into your question for you.
An example of an IF Statement that can be used to add a calculation into the cell you wish to hide if value = 0 but displayed upon another cell value reference.
=IF(/Your reference cell/=0,"",SUM(/Here you put your SUM/))
Use this
=IFERROR((H15+G16-F16)^2/(H15+G16-F16),"")

Count max value (text+number) occurrences with filtering a specific part of text in excel

I'm having an excel column range (including blank cells) something like:
00EGB00-GE001
00EGB00-GE001
00EGB00-GE001
00EGB00-GE001
00EGB00-GE002
00EGB00-GE002
00EGB00-GE002
00EGB00-GE002
00EGD20-GD101
What I need is to Count total number of similar values and I'm stuck with the logic for counting total unique "similar" values... example "GE" & "GD" separately.
How to count total number of unique "GE" values in the list?
I thought =COUNTIF(B:B,"*GE*") should work but it does not. It gives total count of "GE" but I need to find unique count. Example GE001 & GE002 should be considered as 2 values in total.
Kindly help
EDIT AGAIN: Given further clarification below, and assuming that the data always has the same number of digits, one way to do it is by putting this in Column B:
=RIGHT(A1,5)
Then, if you have Excel 2007 or up, Copy and Paste Values and use Remove Duplicates to leave you with the unique values. Then remove the items with GD, either manually or using a formula.
In this case, the output is:
GE001
GE002
In this case, you can easily see that it's 2. If you have lots of values, you can use COUNTA. Is that what you want?
YET ANOTHER EDIT BASED ON LAST COMMENT: this is probably getting closer:
=SUMPRODUCT(--(MID(A1:A9,9,2)="GE"),1/COUNTIF(A1:A9,A1:A9))
Where the "GE" is hard-coded in the formula above you could also substitute a cell reference where you can alter the value.
Or, if you don't know where the text you want will be exactly because the number of characters change, this will work (but you'd need to be careful with what you were searching on because it might repeat somewhere else in the string):
=SUMPRODUCT(--(ISERR(SEARCH("GE",A1:A9))<>TRUE),1/COUNTIF(A1:A9,A1:A9))
Again, you can replace the "GE" with a cell reference.
As discovered below, though -- blank cells will cause this to fail. There IS almost definitely a way to cater for them (maybe using a FREQUENCY based Array Formula), but if you can live with cleaning out the blank cells then that would be one way of doing it.
LAST EDIT: this will account for blank cells. It is an Array Formula, and CAN be used on whole columns, but that will be quite slow as it takes up a fair bit of calculation effort:
{=SUMPRODUCT(--(MID(A1:A9,9,2)="GE"),IF(ISBLANK(A1:A9),1,1/COUNTIF(A1:A9,A1:A9)))}
As it's an Array Formula, use Ctrl + Shift + Enter to input it.

Resources