Is there a formula that can be used to analyse an array (say A1:A10) and return a condense list of that same array but remove all blank cells? The only caveat is, every cell in range A1:A10 is a formula, with some resulting in "", which are visually blank but obviously the cell itself contains a formula.
In the screenshot, the data in A1 is a formula =IF(ISEVEN(ROW()),ROW(),"") so every other row will evaluate to an empty string.
The formula in C2 is the array formula
=IFERROR(INDEX(A:A,SMALL(IF($A$1:$A$10<>"",ROW($A$1:$A$10)),ROW(A1))),"")
Array formulas must be confirmed with Ctrl-Shift-Enter, unless you have an Excel version with the new Dynamic Arrays formulas.
Related
Is IF(ISNUMBER(A1:A100),A1:A100,"") an array formula? If not, what is it?
I copied a list of holidays from a web site and pasted it to Excel. The original data had four columns (date, name of the holiday, weekday, note). After pasting to Excel, everything appeared in column A, like this:
date
name of the holiday
weekday
note
date
name of the holiday
.....
.....
I tried several ways to see if the data could be pasted into columns to no avail. So, I needed to extract the dates to another column. In column B, I entered this formula =IF(ISNUMBER(A1:A100),A1:A100,""). It worked to extract the dates from column A to column B.
I am not sure if it is an array formula as, unlike other array formulae, it doesn't need Ctrl-Shift-Enter. Yet, ISNUMBER usually takes a cell as the argument, not an array, and IF usually doesn't return an array.
IF and ISNUMBER are not array functions, but they can be used in array formulas.
Outside of an array formula, they accept only single input values and return single output values.
In an array formula, they can accept an array of inputs values and will return an array of outputs values.
Without pressing CTRL-SHIFT-ENTER, the formula you've specified is not an array function.
What you're seeing is the behaviour when a function that is expecting a single value is given a range and entered without pressing CTRL-SHIFT-ENTER but the input range overlaps with the row where the formula is placed.
Entering a range when a single value is expected will return the value from the range on the same row in which the formula is entered if it overlaps, otherwise it will return an error.
You are getting output only because you are placing the formula next to the rows being referenced; and it is giving the same result as if you had entered the formula normally and then filled down: i.e. putting =IF(ISNUMBER(A1),A1,"") in cell B1 and filling down.
Note that if you entered =IF(ISNUMBER(A1:A100),A1:A100,"") in cell B2 instead of cell B1 and then filled down, then the values still appear in the same row and not shifted down by a row as you might expect. Again, this is because it looks at the value in the same row just because the range overlaps with the current row.
Compare to putting =IF(ISNUMBER(A1),A1,"") in cell B2 and filling down, where you then get the values shifted down by a row as expected.
If you entered the original formula again in cell B101 (below the input range) and filled down, you get no values at all (even if there is data next to the cell) because the input range no longer overlaps the current cell. In fact, if you used the Evaluate Formula tool from the Formulas tab, you'll see that the range A1:A100 returns a #VALUE error immediately.
This behaviour is confusing and should be avoided at all costs. Only enter ranges when a function expects a range, or when an array formula is being intentionally created using CTRL-SHIFT-ENTER.
If after pasting your data to excel sheet looks like below then you can use following formula.
As shown to above screenshot user below formula to C1 cell then drag down and right as needed.
=INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1))
This formula will produce 0 (zero) for empty cells. To hide zero (0) use a IF() condition like below.
=IF(INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1))=0,"",INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1)))
I have a sumif formula wrapped in a sum formula so I can use an array where if the value in cell G2 equals "All" then I want to add up the values in range B2:B4 for three names in the data, but if the value cell G2 equals one of the three names, ie: Tim, then I just want to add up all the values in range B2:B4 for Tim. The formula works fine if only one name is used, but when I enter "All" into cell G2, only the value for the first name is added up. I'm using the below formula:
=SUM(SUMIF(A2:A4,IF(G2="All",{"Tim","Henry","Mike"},G2),B2:B4))
Thanks in advance for any ideas on how to get this to work.
Just in case these three values are the only occuring values in your list, you could just put this in an IF statement, like so:
=IF(G2="All",SUM(B2:B4),SUMIF(A2:A4,G2,B2:B4))
If you have other names in your lookup column, like so:
Your own formula work just fine using it as array formula. You just had to enter it through Ctrl+Shift+Enter
You could use a formula like:
=IF(G2="All",SUMPRODUCT(SUMIF(A2:A5,{"Tim","Henry","Mike"},B2:B5)),SUMIF(A2:A5,G2,B2:B5))
To prevent you have to enter it as array (it's still technically an array formula!)
No need to hard code the array or for an array formula:
=SUMIF(A:A,IF(G2="All","*",G2),B:B)
In column B I've got the list of values of which some occur multiple times.
What I am trying to achieve is to list unique values of such list in column E. For cell E3 I use the array formula like this:
{=IFERROR(INDEX($B$3:$B$20,MATCH(0,COUNTIF($E$2:E2, $B$3:$B$20), 1)),"")}
but I'm not sure how to add another layer to this formula which would drop all blank cells from B. Now the formula treat blanks as the zero value and returns zero in the first row.
Paste this into D3 and copy down to the cells below to get a unique list of non-blanks value that are in B3:B20:
=LOOKUP(2, 1/((COUNTIF($D$2:D2, $B$3:$B$20)=0)*($B$3:$B$20<>"")), $B$3:$B$20)
You can just enter this normally since it is not an array formula.
It you copy the formula into more cells than there are unique values, you're get #N/A errors. You can avoid this by using IFERROR:
=IFERROR(LOOKUP(2,1/((COUNTIF($D$2:D2,$B$3:$B$20)=0)*($B$3:$B$20<>"")),$B$3:$B$20),"")
(Source)
I want to store the multiple criteria of a SUMIFS function in a single cell with each individual criteria separated by a comma.
I realize you can do this by having each criteria in a separate cell, but I need to have each criteria in a single cell separated by commas (or some other delimiter).
The closest I've gotten is seen in the screenshot below. Cell E4 is the formula if I hard code the criteria (an account of 500 or 600). However, if I put those criteria in the criteria cell, E2, and reference the E2's value/contents through the CELL function, it returns the value "500","600" as """500"",""600""" because it escapes the double quotes and then interprets the value as a text string rather than a list of texts.
Does anyone know how to make cell E2's value be a list of text/strings so that it can be passed into the SUMIFS criteria parameter?
Does it need to be SUMIFS?
If you format E2 as text then input 500,600 you can use this formula for the sum
=SUMPRODUCT(ISNUMBER(SEARCH(","&B2:B8&",",","&E2&","))+0,C2:C8)
See screenshot
I have created a dynamic table in excel through a SUMIFS formula:
=SUMIFS(data!$D:$D,data!$B:$B,Sheet2!B$3,data!$C:$C,Sheet2!B$2,data!$A:$A,Sheet2!$A4)
this is what the table looks like:
while the data looks like:
Now I am picking values from the column Order Total. What I would like to do is to insert a dropdown list on cell B1 to dynamically select from what column I want to get the data.
Is there a way to add this in my formula?
Ok, since order total is in column D, I'll replace the first piece of the sumifs with the indirect, and I'm assuming the data is on the data worksheet, as well as cell B1 which you want the dropdown: =SUMIFS(indirect("data!$"&data!B1&":$"&data!B1),data!$B:$B,Sheet2!B$3,data!$C:$C,Sheet2!B$2,data!$A:$A,Sheet2!$A4)
What the indirect does is concatenate (using the '&' symbol) the string information with the cell information, then change it to a cell reference. If you copy everything within the indirect into another cell (preceded by "="), it would return your original data!$D:$D, if you put "D" in cell B1. This then becomes the cell references for the sumifs formula when using the indirect formula. If you change cell B1 on the Data worksheet to "E", the formula would evaluate to data!$E:$E within the indirect, which would then mean the sumifs formula references column E.