I would like to apply a Filter function on multiple columns ranging from A:G and only have columns B,D in the output. How can I do it?
For Example =FILTER($A$1:$G$7,$K$1:$K$7=$K$1) results in a spilled array of rows that match the condition, but the output will still have 7 columns(A:G). Can I choose to only output Column B & D?
TL;DR
Option1:
=FILTER(FILTER(A1:G7,K1:K7=K1),{0,1,0,1,0,0,0})
Option2: - Reference
=FILTER(INDEX(tblData,SEQUENCE(ROWS(tblData)),{4,3,5}),tblData[Customer Name]=I3)
Option3: - Answered by Rory
=FILTER(CHOOSE({1,2},B1:B7,D1:D7),$K$1:$K$7=$K$1)
Option4: - Commented by P.b
=FILTER(FILTER($A$1:$G$7,$K$1:$K$7=$K$1),(COLUMN(A:G)=COLUMN(B:B))+(COLUMN(A:G)=COLUMN(D:D)))
Explanation
Option 1
You can nest the original FILTER function inside another FILTER function and specify an array of 1's and 0's mentioning which column you need and which you don't.
For Example, in the above question if I want only Column B & D, I can do this:
=FILTER(FILTER(A1:G7,K1:K7=K1),{0,1,0,1,0,0,0})
Since B & D are the 2nd & 4th columns, you need to specify a 1 at that position in the array
Similarly if you want to filter columns from C:K and only output columns C, D & G, then your formula would be:
=FILTER(FILTER(C1:K7,M1:M7=M1),{1,1,0,0,1,0,0,0,0})
Pros & Cons - Option1
This formula is the simplest of all and easy to understand
You can NOT change the order of output. You can only hide/unhide in the original sequence
You can apply this on a Range of multiple columns without much change
Option2
Another way to do this which is complex looking is this:
Note that this method allows you to change the order of output columns. You can refer to following site for detailed explanation on how this works.
=FILTER(INDEX(tblData,SEQUENCE(ROWS(tblData)),{4,3,5}),tblData[Customer Name]=I3)
Pros & Cons - Option2
This formula looks complex, but is straight-forward once you understand the logic
You can change the order of output columns as required
You can apply this on a Range of multiple columns without much change
Options 3
This is actually the answer provided by Rory
=FILTER(CHOOSE({1,2},B1:B7,D1:D7),$K$1:$K$7=$K$1)
Pros & Cons - Option3
This formula is complex, especially for returning a range of continuous columns
You need to explicitly mention each output column individually
You can change the order of output columns as required
Applying this on to output multiple continuous ranges gets tricky (For Example you cannot replace B1:B7 with B1:C7 in above formula)
Options 4
Based on comment from P.b below
=FILTER(FILTER($A$1:$G$7,$K$1:$K$7=$K$1),(COLUMN(A:G)=COLUMN(B:B))+(COLUMN(A:G)=COLUMN(D:D)))
Pros & Cons - Option4
This formula is the simple and somewhat similar to option 1.
You can NOT change the order of output. You can only hide/unhide in the original sequence
You can apply this on a Range of multiple columns without much change
There's a similar question that's asked in reference to Google Sheet. But Google Sheet also has the Query function which explicitly supports choosing specific columns
You could also use CHOOSE like this:
=FILTER(CHOOSE({1,2},B1:B7,D1:D7),$K$1:$K$7=$K$1)
This also allows you to reorder columns in the output by changing their order in the CHOOSE function.
Try the new CHOOSECOLS function (beta channel at time of writing):
=CHOOSECOLS(filtered_array, {2,4})
I use option #2 exclusively these days, but using a range of cells instead of the array.
=FILTER(INDEX(tblZero,SEQUENCE(ROWS(tblZero)),A2:M2),tblZero[TakenBy]=A1)
Using the [#Headers] of my Table gives me column headings as well.
=FILTER(INDEX(tblZero[#Headers],SEQUENCE(ROWS(tblZero[#Headers])),A2:M2),'Zero Dollar Review Data'!A1<>"")
I use the row directly above the column headings to hold the column numbers. This way, I simply have to enter a column number and I get both the column heading and the data. I can also use some simple formulas in my column number cells to create outputs that are custom to the criteria used. So if I enter "TBT" as my TakenBy value I can display a set of columns unique for that particular Rep., then if I enter "DXD", I can display a different set of columns.
By far the easiest way of doing this.
Apply range, your selection of columns in the preferred order and with the option to work your way in from the right side with -
=CHOOSECOLS(FilteredRange,2,4)
=CHOOSECOLS(FILTER($A$1:$G$7,$K$1:$K$7=$K$1),2,4)
=CHOOSECOLS(FILTER($A$1:$G$7,$K$1:$K$7=$K$1),4,2) 'Custom order
=CHOOSECOLS(FILTER($A$1:$G$7,$K$1:$K$7=$K$1),-6,-4) 'From the right side
I have a spreadsheet with Company Name and Serial Number columns. The serial number column values are in range e.g. 1001-2000. How do I look up company name from a specific serial number value? See this screenshot for example.
Column B can be split into two columns if needed though it is preferable to have single column.
I tried this example but got a #Spill! error
Or, using Lookup+Imreal function
In E2, enter formula:
=LOOKUP(D2,IMREAL(B2:B5&"i"),A2:A5)
Be careful with this... It is a crude hack.
=IF(D2<=1000,A2,INDEX(A:A,MATCH(D2+1&"-"&D2,B:B,1)))
in the special case of the ranges all ending at a multiple of 1000 and each band being essentially 1000 units you could go with the special case formula of
=INDEX($A$2:$A$5,INT(($D2-1)/1000)+1)
Note that you don't actually use the info in column B for this option. It is based purely on the pattern to the range breakdown
if you want to restrict it to values between 1 and 4000 you could wrap it in an if statement that checks for that.
=IF(AND(D2>=1,D2<=4000),INDEX($A$2:$A$5,INT(($D2-1)/1000)+1),"SN out of range")
So I'm trying to count data over a large date range, lets say I only need May's data and only the data in May that has a field with a specific entry, I know I need to use COUNTA as the entry are words, but how would I organize the formula? IF (date matches range) then COUNTA IF (cell "X" = Yes) is the best I can come up with as the layout, any help would be appreciated!
Use =COUNTIFS(...). It allows you to use multiple sets of criteria.
For example, you could use something like this
=COUNTIFS(A1:A40,"Yes", B1:B40, ">"&C1)
It would tell you the number of fields with text "Yes" in A1:A40 that have a date in column B greater than the value of C1
You can use COUNTIF as per the screenshot below. This will give you the number of 'May' entries in Column A:
In case you need to find another data in some other columns based upon the condition in column A then it would be a different solution. You will need to explain the problem a bit more clearly with some sample data.
Hope this helps!
Use the following:
=COUNTIFS(Sheet2!$A$2:$A$5000,">="&DATE(2017,5,1),Sheet2!$A$2:$A$5000,"<="&DATE(2017,5,31),Sheet2!$B$2:$B$5000,"<>")
change A2:A5000 to your date column
B2:B5000 to your project column
instead of "<>" write the condition for project
I have an excel column with some interesting data, but a lot of positive and negative values that are insignificant.
So I would like to turn all the values -1<0<1 into zero.
What would be the best way to do this?
Any help would make my day.
You could use a simple IF condition for this task.
Assuming you have your data in column A, use the below formula in column B and drag it down,
=IF(AND(A1<=1,A1>=-1),0,A1)
You could later use this column as reference. If you want to ignore 1 and -1 , then remove the = sign within the AND function.
=IF(AND(A1<1,A1>-1),0,A1)
I have a (large) array of data in Excel of which I need to compute the average value of certain values in one column, based on the values of another column. For example, here's a snippet of my data:
So specifically, I want to take the average of the F635 mean values corresponding with Row values of 1. To take it a step further, I want this to continue to Row values of 2, Row values of 3 etc.
I'm not familiar with how to run code in Excel but have attempted to solve this by using the following:
=IF($C = "1", AVERAGE($D:$D), "")
which (to my understanding) can be interpreted as "if the values (anywhere) in column C are equal to 1, then take the average of the corresponding values in column D."
Of course, as I try this I get a formula error from Excel.
Any guidance would be incredibly appreciated. Thanks in advance.
For more complicated cases, I would use an array-formula. This one is simple enough for the AVERAGEIF formula. For instance =AVERAGEIF(A1:A23;1;B1:B23)
Array-formula allows for more elaborate ifs. To replicate the above, you could do =SUM(IF($A$1:$A$23=1;$B$1:$B$23;0))/COUNT(IF($A$1:$A$23=1;$B$1:$B$23;0)).
Looks like more work but you can create extremely elaborate if-statements. Instead of hitting ENTER, do CTRL-ENTER when entering the formula. Use * between criteria to replicate AND or + for OR. Example: SUM(IF(($A$1:$A$23="apple")*($B$1:$B$23="green");$C$1:$C$23;0)) tallies values for green apples in c1:c23.
Your sample data includes three columns with potential ifs so my guess is that you're going to need array formulas at some point.
Excel already has a builtin function for exactly this use; AVERAGEIF().
=AVERAGEIF(C:C,1,D:D)