MS Excel create virtual column to use in formula - excel

I want to do something similar to summing 1/x from 1 to 100 without creating an extra column to help with the calculation. I want my first column to be the numbers 1 through 100. And I want a cell to show the sum of 1/x where x is each cell in the first column. Currently the only way I can think to do this is to create a second column to do 1/x for each individual cell then sum the second column. Is there any solution to doing this without having to create the second column?
Thanks!

You can use this "array formula"
=SUM(1/A1:A100)
confirmed with CTRL+SHIFT+ENTER
....or avoid array entry by using SUMPRODUCT
=SUMPRODUCT(1/A1:A100)
both versions assume you don't have zeroes (or blanks) in A1:A100
if you might have zeroes or blanks then use this array formula
=SUM(IF(A1:A100,1/A1:A100))

if you mean 1 + 1/2 + 1/3 + ... + 1/100, use following array formula (entered by Ctrl+Shift+Enter instead of just Enter):
=sum(1/row(A1:A100))

You need to use an array formula as below:
{=SUM(1/A1:A100)}
where A1:A100 contains 1 to 100
You create the array formula bu typing the formula as =SUM(1/A1:A100) and then pressing Control-Shift-Enter.
If you do it correctly the formula then shows up with the curly brackets {} but you don't enter the curly brackets yourself.

Related

Lookup excel return min value if no match found

If number from first coulmn is found in the second column, it should return that number.
If number from first coulmn is not found in the secound column, it should return closest possible min value
You can use vlookup() like this, BUT you need to sort the values:
In C1 enter the array formula:
=MAX(IF(B:B<=A1,B:B))
and copy downward:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
NOTE:
Sorting is not required.
Array entry is not required if you are using Excel 365.
Another option is SUMPRODUCT:
=SUMPRODUCT(MAX(--($B$1:$B$12<=A1)*$B$1:$B$12))
It works on Excel 2007 or higher, no need of array entered formula and no need of sorting.

Excel: apply formula to each cell before SUM operation

I am trying to do a SUM on a range of cells but instead of using the value in the cell as IS I need to extract a piece from each cell to use in the sum. In the example below I need to use the value before the - sign.
A
1 1-3
2 2-60
3 5-3
4 =SUM(A1:A3)
SUM should be the addition of the first piece (before the -) so 1 + 2 + 5
I found a way to extract the data by using
=LEFT(A1, SEARCH("-",A1,1)-1) = 1
=LEFT(A2, SEARCH("-",A2,1)-1) = 2
=LEFT(A3, SEARCH("-",A3,1)-1) = 5
But how can I SUM the value of these formulas without having to use any more additional cells?
Use an array formula: =SUM(VALUE(LEFT(A1:A3, SEARCH(A1:A3, "-")-1))). Then press Shift-Ctrl-Enter to tell Excel this is an array formula.
sumproduct alternative
=SUMPRODUCT(--(LEFT(A1:A3,FIND(A1:A3,"-")-1)))
This is a none CSE formula that peforms array like operations. As such you should avoid full column references within the sumproduct. Also note, things may go a little "WONKY" if there is no - in the cell. To avoid that you could add a - to the very end. Formula would look something like this:
=SUMPRODUCT(--(LEFT(A1:A3&"-",FIND(A1:A3&"-","-")-1)))
That will work when you just have integers and no formula

Count/Sum a column but exclude #N/A

Currently using the following forumlas to count the number of records in all of column Z that does not have #N/A but it does not work. All the rows in Column Z have a formula itself (Which is why some of them display #N/A, its a VLOOKUP).
=COUNTA(Z:Z)-SUM(IF(ISNA(Z:Z),1))
=SUMPRODUCT(--(TRIM(Z:Z)<>"#N/A"))
These return a "0" value which is not true, what am I doing incorrect?
If you are using Excel 2010 or later, to count non-error values you can use (regular formula)
=AGGREGATE(3,6,Z:Z)
No reason to use an array formula for this, you can just do something like
=COUNTIFS(Z:Z, "<>#N/A",Z:Z, "<>")
or
=COUNTA(Z:Z) - COUNTIF(Z:Z,"=#N/A")
The first one counts every nonblank, non #N/A cell. The second does what you're trying to do now and subtracts the total of #N/A cells from the total of every nonblank cell. Maybe using ISNA is technically more correct or faster, but this probably works just as well for most cases.
This array formula sums the cells of range Z:Z that are not NA's :
=SUM(IF(NOT(ISNA(Z:Z)),Z:Z)) Ctrl+Shift+Enter
This one (which is probably what you want) sums all but errors:
=SUM(IF(NOT(ISERROR(Z:Z)),Z:Z)) Ctrl+Shift+Enter
And another (simpler) one
=SUM(IFERROR(H:H, 0)) Ctrl+Shift+Enter
Are you entering it as an array formula? Press Ctrl-Shift-Enter instead of just enter. I think the first formula should work.
=COUNTA(Z:Z)-SUM(IF(ISNA(Z:Z),1))

Excel find lower distinct value in list

I'm trying to find in a list the lowest unique value.
I tried to find out a way on google, but nothing seem to work like I want.
What i have :
John;5
Leon;7
Mark;5
Bob;3
Peter;3
Louis:4
Desired result: "4" because it's the lower unique value.
Suppose I add in the original list:
Alex;4
The new result is about to be "7" because it's the new lowest unique value.
my excel sheet :
Assuming your data is setup so that names are in column A and values are in column B so that it looks like this:
In cell D2 (or wherever you want the result), use this array formula (Note that array formulas must be confirmed with CTRLSHIFTENTER and not just ENTER):
=MIN(IF(COUNTIF(B2:B20,B2:B20)=1,B2:B20))
You'll know you've entered it as an array formula correctly because you'll see it surrounded by curly braces {=formula}in the formula bar. Do NOT add the curly braces manually.
You'll also notice that I have extra rows in there than just the used rows. Normally I'd suggest using a dynamic named range, but this works for now. So when you add the new line of Alex; 4, you get this:
And you can see the formula now has the new correct value of 7.
With data in columns A and B, in C1 enter:
=COUNTIF(B:B,B1)
and copy down. Then in another cell enter the array formula:
=MIN(IF(C:C=1,B:B))
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
To avoid speed problems, make the limits on the ranges as small as possible:
=MIN(IF(C1:C6=1,B1:B6))

Find blank count in a row with most blanks within a 2D array of cells

I want a formula that will look in a 2D array of cells for the row that has the most blank cells in it. Then I want the number of that row's blank cells returned as shown in the picture. The "Title 2" row has the most blanks at 4 as displayed in B8. I would want the formula to take the whole table into considerations, so cells B2:G5
Or this array formula**:
=MAX(MMULT(0+(LEN(B2:G5)=0),TRANSPOSE(COLUMN(B2:G5)^0)))
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
Sometimes it's easier to break things up into two tasks:
A formula in Column H that counts blanks by row. Something like: =COUNTIF(B2:G2, "="&"") which you would drag down through row #5.
Then, just make Cell B8 the maximum of that new column: =MAX(H2:H5).
I'd be curious if there is some type of array formula trick to accomplish this is one formula. Nevertheless, personally, I find separating the logic into smaller, more manageable, formulas easier to maintain.
In H2 enter:
=COUNTBLANK(B2:G2)
and copy down. In B8 enter:
=MAX(H2:H5)
For example:
Several great answers already, but I'll throw this out there:
=MAX(COUNTBLANK(INDIRECT("B"&ROW(2:5)&":"&"G"&ROW(2:5))))
Enter as an array formula: Ctrl+Shift+Enter
This:
"B"&ROW(2:5)&":"&"G"&ROW(2:5)
… returns an array of strings {"B2:G2" , "B3:G3" , "B4:G4" , "B5:G5"}:
That array is fed to the INDIRECT function, which changes it into an array of ranges {B2:G2 , B3:G3 , B4:G4 , B5:G5}.
That new array is fed to the COUNTBLANK function, which (using your example) returns the array of numbers {2 , 4 , 1 , 3}.
That's fed to the MAX function, so the end result is the number 4.
It's a bit convoluted, so I'm wondering if my INDIRECT parameter can be simplified.

Resources