FILTER function on column containing numbers, text and empty cells - excel

0
A
B
C
1
Year
From
1974
2
2004
To
2005
3
2016
Result
3
4
1996
5
6
no info
7
1974
8
no info
9
10
11
12
In Cell C3 I want to count the rows in Column A where the year is
a) >= the value in Cell C1 AND
b) <= the value in Cell C2
Therefore, I implemented this formula:
=ROWS(FILTER($A$2:$A$12,($A$2:$A$12>=C1))*($A$2:$A$12<=C2))
However, this formula returns 11 as result which is probably caused by the empty cells and the no info input in Column A.
To avoid that those inputs are considered in the count of the rows I tried to go with this:
=ROWS(FILTER($A$2:$A$12,($A$2:$A$12>=C1))*($A$2:$A$12<=C2)*($A$2:$A$12<>"")*($A$2:$A$12<>"no info"))
However, this formula still returns 11 as result.
How do I have to modify it to get the correct values?

What about COUNTIFS()? Try-
=COUNTIFS(A:A,">="&C1,A:A,"<="&C2)
and with FILTER() try-
=ROWS(FILTER($A$2:$A$12,($A$2:$A$12>=C1)*($A$2:$A$12<=C2)))

You've put double close brackets )) too early in your formula, ending the Filter() function and then putting additional conditions outside of it.
Change the formula to
=ROWS(FILTER($A$2:$A$12,($A$2:$A$12>=C1)*($A$2:$A$12<=C2)*($A$2:$A$12<>"")*($A$2:$A$12<>"no info")))

Related

How to SELECT N values ABOVE and BELOW from specific value

If I have a table:
Column A
Column B
Column C
1
Jane
10
2
Stewe
9
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
10
Carol
1
I would like to SELECT 3 rows above and below WHERE Column B = someValue .
IF query SELECT * WHERE Column B = "Andrew" result should look like:
Column A
Column B
Column C
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
I know how to select one row, but cant understand how to select such range.
Thanks for ideas!
You can limit and offset inside your QUERY():
=QUERY(A1:C,"limit "&2+MIN(5,MATCH(D1,B:B,0))&" offset "&MAX(0,MATCH(D1,B:B,0)-5))
Well, this was fun...
If 3 above or below are not available then blank... rolling data around is a different proposition.
Below the image is the list of formulae used.
So, per cell not including the data validation that is based on cells B2:B11
A14 and dragged down:
=IFERROR(INDEX($A$2:$A$11,MATCH(B14,$B$2:$B$11,0)),"")
C14 and dragged down:
=IFERROR(INDEX($C$2:$C$11,MATCH(B14,$B$2:$B$11,0)),"")
Cells B14 through B20:
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=3,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-3)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=2,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-2)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=1,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-1)),"")
=E2
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+1),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+2),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+3),"")
In Excel 365, you could try:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
In Google sheets, on the other hand, the formula would be:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
(spot the difference).
Excel
Google Sheets
This should produce what you want in all cases:
=IFERROR(FILTER(A2:C,B2:B<>"",ROW(A2:A)>=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)-3,ROW(A2:A)<=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)+3))
Of course, you can replace the two instances of "Andrew" with a cell reference (one where you type a changeable name).
This just looks up the row in a curly-bracket array formed from the names and row numbers and uses FILTER to keep results to rows between +/-3 rows of where the target name is found. If you choose the first name (or any other name), you won't get an error; because even if the target name were on Row 1 and the formula goes looking for anything "greater than or equal to 1 minus 3, all rows will be greater than a negative number. Same on the high end. You just won't get a full seven names if there aren't at least three other rows prior to or after the target row.
this not the best solution but it will work , you can use a helper column 'D' that contains the following formula =if(countif(INDIRECT("B"&ROW()+3&":"&"B"&ROW()-3),"Andrew")>0,TRUE,FASLE)
and u can query from here like this SELECT * WHERE Column D = TRUE

VLOOKUP if only a part of the search criteria matches with the values in the table

I have the following Excel spreadsheet:
A B C
1 List Search Criteria Result
2 2019-01 9 2019-09
3 2019-02
4 2019-03
5 2019-04
6 2019-05
7 2019-06
8 2019-07
9 2019-08
10 2019-09
11 2019-12
12
In Column A I have a list of all months in 2019. In Cell B2 I want to search for a month by just enterring in the number of the month. The result should appear in Cell C2. Therefore, I tried to go with the following formula in Cell C2:
C2 =VLOOKUP(B2,$A$2:$A$13,1,FALSE)
The issue is now that basically my search criteria is not 2019-09. It is just 9 and therefore the VLOOKUP is not able to find it within Column A.
So far I came up with the following solutions to solve this issue:
a) Change the search criteria to ="2019-"&B2.
b) Add a helper column next to Column A in which I only dsiplay the number of the months
However, I am wondering if there is smarter solution which does the job within the VLOOKUP function directly (maybe a combination with the MID function)?
Based on the comments below the question there are two solutions to solve the problem:
Option A)
If the year in the list does not change and will be the same you can go with this formula:
=VLOOKUP(TEXT(B2,"\*00"),$A$2:$A$13,1,FALSE)
Option B)
If the year in the list changes you can go with this formula and edit the first parameter accordingly:
=VLOOKUP("2019-"&TEXT(B2,"00"),$A$2:$A$13,1,FALSE)

Select next higher number in array based on a minimum criteria

I have the following Excel spreadsheet:
A B C D
1 0 0.99 Minimum: 6
2 1 0.99 Input: 3
3 2 2.99 Result: 4.99
4 3 2.99
5 4 4.99
6 5 4.99
7 6 7.99
8 7 7.99
9 8 9.99
10 9 9.99
The formula in cell D3 is:
=LARGE(B$1:B$10,COUNTIF(B$1:B$10,">"&D2))
This formula selects the next highest number in the array in
Column B based on the input in cell D3.
For example:
If the input in cell D3 is 3 it will select
4.99 instead of 2.99.
All this works perfectly with the formula in cell D3.
However, now I want to insert a minimum criteria into this system
in cell D1.
For example: If the minimum is 6 the formula in cell D3 should notice it
and select 7.99 instead of 4.99.
Do you have any idea how to solve this issue?
Is there a way to do it without using an array formula?
You can use COUNTIFS to include multiple criteria, instead of your COUNTIF.
So in Cell D3 put the formula below:
=LARGE(B$1:B$10,COUNTIFS(B$1:B$10,">"&D2,B$1:B$10,">"&D1))
It means that the formula is searching for 2 criterias:
Cells Value is larger than value in Cell D2 (Input).
Cells Value is larger than value in Cell D1 (Minimum).
Using INDEX/MATCH you could restrict the range that's looked at, although I feel there's a better way:
=LARGE(INDEX($B:$B,MATCH($D$1,$A:$A,0)):INDEX($B:$B,COUNTA($A:$A)),COUNTIF(INDEX($B:$B,MATCH($D$1,$A:$A,0)):INDEX($B:$B,COUNTA($A:$A)),">"&$D$2))
You could place the INDEX/MATCH into a named range to make the formula shorter.

Excel table : how can I change row and column?

I have a table excel with one column and X rows.
4 various informations
example:
row 1 2 3 4 = informations for 1
row 5 6 7 8 = information for 2
I would like to know how can I do to have these information by row instead of by column?
Example:
paul
madrid
14
victor
canada
23
emilie
paris
18
and I Would like:
paul Victor Emilie
Madrid Canada Paris
14 23 18
If you want change data only once, use Copy/Paste
Switch (transpose) columns and rows
Or if you want use formula
TRANSPOSE function
Or you can use the INDIRECT function instead. It's a bit tricky but it works :
On the same sheet where you have :
Paul
Madrid
23
Victor
Montréal
22
Aude
Copenhague
17
Valérie
Alger
28
Add something like (for example on columns B, C, D) :
1 2 3
4 5 6
7 8 9
10 11 12
etc.
It's easy to do with =X+3 formula and drag down formula.
Then, this matrix represent the position of each element in the list, you now just have to use INDIRECT in this way :
=INDIRECT("A" & B1)
A is the column where are your data
B1 is the position of the first element in the matrix
By draging this formula down and on the right, you will the matrix with the A's elements.
(Using example where source column in G2:G100 and target table in H2:J34.)
Type formula below in first cell of target table (H2):
=OFFSET($G$2;(ROW()-ROW($2:$2))*3+COLUMN()-COLUMN($H:$H);0)
Replacing $G$2 with first cell of source data, $2:$2 with first row of target table and $H:$H with first column of target table (mind the $).
Then just drag formula left and then bottom.

formula for finding the first non-empty cell

I have a spreadsheet with 2 columns of data, column A and B, and column C where I'm looking for the formula.
row A B C
1 50
2
3
4
5 56 6
6
7
8 46 10
9
10
11 64 18
As you can see, a row either contains a value or not. In column C, I'm looking to calculate the difference between
a) the value in column B and the value in column A's first non-empty cell directly above (so for example, at row 5, I calculate the difference between B5 and A1 56 - 50 = 6) if the value of B is a number and
b) the value in column A and the value in column B's first non-empty cell directly above (row 8, 56 - 46 = 10)
and put nothing if neither column A and B are empty.
I've been struggling with "first non-empty cell" to write an R1C1 formula. Note that I know I can do this in VBA but I'm looking for the R1C1 formula.
Thanks for your help.
Here is an array formula (that you need to validate with Ctrl + Shift + Enter) you can put in C1 and drag and drop till the end of your data:
=IF(OR(A1<>"",B1<>""),INDEX($B$1:B1,MAX(IF($B$1:B1="",0,ROW($B$1:B1))))-INDEX($A$1:A1,MAX(IF($A$1:A1="",0,ROW($A$1:A1)))),"")
Or, in a french version of Excel:
=SI(OU(A1<>"";B1<>"");INDEX($B$1:B1;MAX(SI($B$1:B1="";0;LIGNE($B$1:B1))))-INDEX($A$1:A1;MAX(SI($A$1:A1="";0;LIGNE($A$1:A1))));"")
Note that if you feel interested, you can commit into Stackoverflow in french
Perhaps try this formula in C2 copied down
=IF(B2="",IF(A2="","",LOOKUP(9.99E+307,B$1:B1)-A2),B2-LOOKUP(9.99E+307,A$1:A1))

Resources