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)
Related
I have 2 columns one is a period and another is a cycle. I need to create a 3rd column where I create a cycle identifier. Where the Letter changes on the cycle but resets every period.
I seem to have it with the following formula
IF(A1<>A2,1,IF(B1<>B2,C1+1,C1)). Which will give results of 1, 2 or 3. Then to get the numbers into letter form by using a switch SWITCH(C1,1,"A",2,"B",3,"C") in an adjacent cell. However I was curious if there is a more efficient or better way to accomplish this perhaps in all in one formula.
Any suggestions would be greatly appreciated.
Period & Cycle
Copy this formula to cell C2 and copy it down.
=IF(B2<>B1,IF(A2<>A1,CHAR(65),CHAR(CODE(C1)+1)),C1)
In Excel 365, you could use a spill formula like this:
=CHAR(B2:B15-XLOOKUP(A2:A15,A2:A15,B2:B15)+65)
You could argue that this is less efficient because it uses a lookup so there could be a speed hit with large amounts of data. On the other hand, it could be considered more efficient because it is a single formula and doesn't need to be pulled down.
If you were worried about the speed, you could set the binary search option in xlookup:
=CHAR(B2:B15-XLOOKUP(A2:A15,A2:A15,B2:B15,,2)+65)
(Column A has to be sorted ascending for this to work - I'm fairly sure that where there are duplicates this will still give the first match. However Microsoft are quoted as saying that there is only a slight benefit of using binary search according to this and other articles)
You could make the formula more dynamic:
=CHAR(B2:INDEX(B:B,COUNTA(B:B))-XLOOKUP(A2:INDEX(A:A,COUNTA(A:A)),A2:INDEX(A:A,COUNTA(A:A)),B2:INDEX(B:B,COUNTA(B:B)))+65)
Or using Let
=LET(Period,A2:INDEX(A:A,COUNTA(A:A)),
Cycle,B2:INDEX(B:B,COUNTA(B:B)),
CHAR(Cycle-XLOOKUP(Period,Period,Cycle)+65))
I am new to Excel/Google Sheets. I have a difficulty of writing a formula to compare columns as a pair-wise since the formula would be
so big as the day goes.
For example, there're 2 main columns Foo and Bar. I want to find the total number of days that Foo
and Bar are equal so the current formula is =IF(A3 = G3, 1, 0)+IF(B3 = H3, 1, 0)+IF(C3 = I3, 1, 0)+...
But this is kind of tedious because there're ~40 days to compare with. Are there any other alternatives
to write a formula in efficient way? Either Google-App-Scripts or Excel Formula is appreciated.
Cheers!
Give a try on below google-sheet formula. Adjust ranges as you need.
=ArrayFormula(SUM(IF(A3:E3=G3:K3,1,0)))
Assuming that you're needing to get such a total for each row and not merely a single row, try this:
=ArrayFormula(IF(A3:A="",,MMULT(IF(A3:F=G3:L,1,0),SEQUENCE(COLUMNS(A:F),1,1,0))))
Of course you will need to adjust the three ranges to match your own FOO and BAR ranges.
This one formula will produce all results for all rows.
The MMULT function is tricky to explain to those as yet unfamiliar with it. But it's a powerful tool. I'll add a picture I created that may best explain what it does:
By making the second matrix a simple SEQUENCE of 1s as long as the other matrix is wide, we wind up multiplying everything by 1 before adding together. And since anything multiplied by 1 is itself, this combination serves only to do a row-by-row add.
Things to keep in mind with MMULT:
1.) Every cell in every matrix must be a number or it will produce an error.
2.) As in the above formula, there are ways to use either/or conditions to turn every cell in a matrix into a number.
Right now I need to sum up some values in certain cells in Excel that are unstructured with text like this:
Netherlands (325)
Belgium (214)
Australia (970)
etc.
So I am only interested in the total value. Of course I could clean the cells and separate the value from the text and sum it up. But I was wondering if there is a fast solution in excel to ignore the text and just take the value in the cell, since this kind of scenario happens often in daily business.
Best regards!
No, you will must have some a bit more complex formula to accomplish this, as far as I am informed, you cant just take in consideration numbers from text only.
In your case, if A1 is "Netherlands (325)", you would have to filter out number with something like =MID(A1, SEARCH("(", A1)+1, (SEARCH(")", A1)) - (SEARCH("(", A1)+1)), and then sum that column.
Eventually, if you dont want to take another column for numbers, you can do similar thing as upper one, with array formula.
Are your values always 3 numeric characters? Then yes here you go:
=SUMPRODCUT(0+RIGHT(SUBSTITUTE(A1:A3,")",""),3))
Thanks for the formulas so far. What I just experienced is, if you type
in the number of the first cell manually next to it, excel auto fills all cells beneath with the corresponding numbers of the other fields. That is super handy and fast I guess.
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.
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.