How to determine the smallest index under a special condition? - excel

In the following example:
A B
1 bar
2 3.0 foo
3 4.0 foo
------------------------
4 1.0 bar
------------------------
5 2.0 bar
6 5.0 bar
7 foo
I would like to get the smallest row index i (that is 4 in our case), for which B(i)="bar" and A(i) is not an empty cell. Could you please suggest a formula/VBA macro for this task?

A nice and simple MINIFS should do what you want.
=MINIFS($A$2:$A$8,$B$2:$B$8,"<>",$C$2:$C$8,"bar")
This just return the minimum index where A is not blank, and B is "bar".
EDIT - Adding an alternative solution using MATCH
Using MATCH is a little more complicated, but works on older versions of Excel and doesn't require the Index column like the previous example does:
=MATCH(1, INDEX(($B$2:$B$8<>"") * ($C$2:$C$8="bar"), 0, 1), 0)

Related

Find all values in Column A which are present in Column B

Consider the sheet below:
A
B
1
4
3
5
2
2
5
0
4
1
I want to find if there is a match for each row of column 1 with any row of column 2. So ideally this would give me:
A
B
C
1
4
Yes
3
5
No
2
2
Yes
5
0
Yes
4
1
Yes
As a first and simple step, I am using =MATCH(A2,B2:B6) to get the index of the match and then manually calling this across the rows to get something like this:
A
B
C
1
4
6
3
5
-
2
2
3
5
0
2
4
1
1
I am now having a problem:
I want to apply this for a row of 500 in A and 2000 in B. I was thinking of manually filling in the first few rows and then select and drag over the first 500 rows. This however does not work as for each subsequent cell, it just changes the formula to =MATCH(A(N +1),B2 + N:B6 + N) which gives me wrong values and at worst, just repeats the older pattern ahead.
Can anyone help me with how I can just use the MATCH function to find all the values in A that are present in B?
Let me continue where you arrived:
=MATCH(A2,B2:B6,0)
(You forgot the last zero)
This formula is correct, but it is also wrong.
???
Well, when you drag it down, you get:
=MATCH(A3,B3:B7,0)
This is not what you want: you want the search term (A2) to change into A3 but you want the search array (B2:B6) not to change. In order to get this done, you need to work with absolute references. This looks like this:
=MATCH(A2,B$2:B$6,0)
When you drag this down, this is what you get:
=MATCH(A3,B$2:B$6,0)
=> ok so far.
Problem now: you need to translate your current results (a number or #N/A) into "yes" or "no". This can be done in numerous ways, let me give you an example:
=IF(ISERROR(MATCH(A2,B$2:B$6,0)),"No","Yes")
One remark: there exists an IFERROR() function in Excel, but this does not have an "else"-clause, hence the choice for the IF(ISERROR( combination.
Within Sheets you may try this out:
=index(if(len(A2:A),if(ifna(xmatch(A2:A,B2:B)),"Yes","No"),))
If you want to separate those matching values then could use FILTER() function.
=FILTER(A1:A5,COUNTIFS(B1:B9,A1:A5))
And for YES, NO dynamically, try MAP() function.
=MAP(A1:A5,LAMBDA(x,ISNUMBER(XMATCH(x,B:B))))

How to use Index, Match and Product functions in excel for this questions?

Week # 1 2 3 4 5
Ratio 0.9 0.9 0.8 0.8 0.6
Select week from Drop Down List ____ (we have 1,2,3,4,5 inside)
So how can we use index,match,product or other excel formulas for performing the following task:
If 3 is selected from the dropdown list, then we multiply 0.90.90.8
If 2 is selected from dropdown list, then we multiply 0.9*0.9
Can you please help?
I could not find how to use index match or this
You can use PRODUCT and INDEX to achieve this. No need for MATCH here. Take a look at this example:
A
B
C
D
E
F
G (your dropdown)
H
1
week
1
2
3
4
5
3
=PRODUCT(B2:INDEX(B1:F2,2,H1))
2
ratio
0.9
0.9
0.8
0.8
0.6
In case your weeks do not start at one, you do have to use MATCH:
=PRODUCT(B2:INDEX(B2:F2,1,MATCH(H1,B1:F1)))
with Office 365 you could also do this using TAKE:
=PRODUCT(TAKE(B2:F2,,H1))
Where H1 is the dropdown selection:
Else use =PRODUCT(B2:INDEX(B2:F2,,H1))

Excel - Include Row in Sum Based on Comparison to Following Row

Paging All Excel Wizards,
I am trying to see if there is a way to have a one-line SUMIF or something similar to sum up the following criteria in an Excel spreadsheet:
Sum the values of Column C if
If Column A = "Chizzle"
AND If Column B is >= Column B of the next row
Sample Data:
A B C
Type Level Value
__________________
Chizzle 1 23
Chizzle 2 10
Bobbles 3 1.5
Bobbles 3 2.6
Chizzle 2 5.5 <- Should Be counted
Cobbles 2 1
Chizzle 1 3.3 <- Should Be counted
I have tried using something like this:
=SUMIFS(C1:C1000,A1:A1000,"Chizzle", B1:B1000, ">=" & B2:B1001 )
Unfortunately the B2:B1001 part isn't working and it is selecting all values.
If there is a way to do this with a one line calculation, without having to add an additional column? That would be awesome but I'm not sure if it is possible.
Thanks!
Try this SUMPRODUCT():
=SUMPRODUCT(($A$2:$A$8="Chizzle")*($B$2:$B$8>=$B$3:$B$9)*($C$2:$C$8))

Excel - get the highest number in a certain column, that contains text

I have these two sheets, that I'm using to keep track of my work. In one of the sheets, I have my overview, where I can see all of my tasks at hand. In other sheets, I have the different jobs I'm currently doing.
Now... I'm looking for at formula for Microsoft Excel, where I can do the following:
="GET THE HIGHEST ROW-NUMBER, IN A CERTAIN COLUMN, THAT ISN'T EMPTY, AND PUT THE TEXT FROM THAT COLUMN INTO ANOTHER CELL" (see examples of it further down)
Examples:
Let's say, that I insert this formula into D10, and to check the entire A-column, then this would be the result
Ex.1
A B C D
1 Foo
2 Bar
3 Is
4 An
5 Apple
6 From
7 Chile
8
9
10 Chile
Ex.2
A B C D
1 Foo
2 Bar
3 Is
4 An
5 Apple
6
7
8
9
10 Apple
Ex.3
A B C D
1 Foo
2 Bar
3 Is
4
5
6
7
8
9
10 Is
Ex.4
A B C D
1 Foo bar is
2 Also an
3 Egyptian God
4 Of pie
5
6
7
8
9
10 Of pie
On a last remark... Then I'm using this stupid danish version of Excel, so if you're a dane trying to solve this, then a danish formula would be 'B-E-A-UTIFUL'.
And remember, that it has to work across different sheets.
MY ATTEMPTS:
I Google around for about an hour... I found this, which I tried to understand:
=INDIRECT(CONCATENATE("R",MATCH(MAX(S4:S5),S4:S5,0)+3))
But I couldn't get it to work, because of this stupid danish Excel. I tried to understand it, then - and figured out, that it parsed and concatenated area as text and inserted that into the field - so I guess that wouldn't do the trick anyways.
Then my idea was to try to loop through all the cells in a column and check each of the cells, if they weren't empty, and if their row-number where higher than then previous. I quickly gave up on that one, because I couldn't find a way to make a for loop in Excel.
Then I've tried all other sorts of things (mainly experimenting with the MAX()-function).
If your data is in a sheet called data then try this formula to get the last text value in column A of that sheet
=LOOKUP(REPT("z";255);Data!A:A)
In Danish that should be
=SLÅ.OP(GENTAG("z";255);Data!A:A)

Count how many values have duplicates in a column

I have values in a column like:
08FHI800
08FHI800
08FHI800
07FJM933
07FJM933
89MNA900
I need a formula that tells me how many items in the column have corresponding duplicates. In this case, it would be 2.
Try this formula assuming data in A2:A100
=SUMPRODUCT((A2:A100<>"")/COUNTIF(A2:A100,A2:A100&"")-(COUNTIF(A2:A100,A2:A100&"")=1))
It will ignore blanks
=SUMPRODUCT((A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")-(COUNTIF(A1:A12,A1:A12&"")=1))
Using this data as an example
Row# ColA
1 1
2 2
3 2
4 2
5 3
6 4
7 5
8 5
9 6
10 6
11 6
12 7
Break the function apart into 3 components:
(A1:A12<>””)
COUNTIF(A1:A12,A1:A12&””)
COUNTIF(A1:A12,A1:A12&””)=1
Component 1
(A1:A12<>””) evaluates to an array containing {T, T, T, T, T, T, T, T, T, T, T, T} ---------(1)
Component 2
COUNTIF(A1:A12,A1:A12&””)
evaluates to
COUNTIF({1,2,2,2,3,4,5,5,6,6,6,7},{1,2,2,2,3,4,5,5,6,6,6,7}
and it counts the number of times each value appears in the range
This in turn evaluates to:
{1,3,3,3,1,1,2,2,3,3,3,1} -----------------(2)
(the &”” is to avoid #DIV/0 error)
Now, because of the brackets we need to evaluate (Component 1 / Component 2) first before looking at Component 3.
Component 1/Component 2 is
(A1:A12<>"")/COUNTIF(A1:A12,A1:A12&"")
So from (1) and (2),
{T,T,T,T,T,T,T,T,T,T,T,T}/{1,3,3,3,1,1,2,2,3,3,3,1}
which evaluates to:
{1,0.3333,0.3333,0.3333,1,1,0.5,0.5,0.333,0.333,0.333,1}
Now we can look at
Component 3
COUNTIF(A1:A12,A1:A12&””)=1
We already have the first bit of this:
COUNTIF(A1:A12,A1:A12&””)
from (2), which evaluates to
{1,3,3,3,1,1,2,2,3,3,3,1}
Combining this with =1 becomes
COUNTIF(A1:A12,A1:A12&””)=1
Which in turn evaluates to
{T,F,F,F,T,T,F,F,F,F,F,T}
So, finally combining this all together, we have
SUMPRODUCT({1,0.3333,0.3333,0.3333,1,1,0.5,0.5,0.333,0.333,0.333,1} - {T,F,F,F,T,T,F,F,F,F,F,T})
Now, T equates to 1 and F equates to 0 so this now becomes:
SUMPRODUCT({1-1,0.333-0, 0.333-0, 0.333-0,1-1,1-1,0.5-0,0.5-0, 0.333-0, 0.333-0, 0.333-0,1-1}
Becomes
SUMPRODUCT({0,0.333,0.333,0.333,0,0,0.5,0.5,0.333,0.333,0.333,0}
As there is only one array, SUMPRODUCT simply sums the elements
1+1+1 =3
There are 3 items which are duplicated.

Resources