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

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))

Related

How to determine the smallest index under a special condition?

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)

perform function on criteria in SUMIF function

I am writing a SUMIF function on a range with a format such as:
A B
1 1.1 5
2 1.2 5
3 1.3 5
4 2.1 5
5 2.2 5
I want the SUMIF to group values together by their integer, i.e.:
A B
1 1 15
2 2 10
I can do this by creating a third column C and applying INT(A) so that:
A B C
1 1.1 5 1
2 1.2 5 1
3 1.3 5 1
4 2.1 5 2
5 2.2 5 2
and (for 1)
=SUMIF(C:C, 1, B:B)
Is there a way to do this in one cell? i.e.
=SUMIF(A1:A5, "int(range) = 1", B1:B5)
I have also tried:
=SUMIF(A1:A5, "1*", B1:B5)
and
=SUMIF(A1:A5, 1&"*", B1:B5)
But these also do not work
You can use SUMPRODUCT e.g.
=SUMPRODUCT(--(INT($A$1:$A$5)=C1),$B$1:$B$5)
INT($A$1:$A$5)=C1 produces an array of TRUEs and FALSEs. The -- operator converts that to an array of 0s and 1s. Then you multiply by the values in B.
Formula in cell F12 is:
=SUMIFS($B$1:$B$5;$A$1:$A$5;">="&E12;$A$1:$A$5;"<"&E12+1)
Drag down
With Excel 365 you can do it like-
=LET(x,UNIQUE(INT(A1:A5)),y,SUMIFS(B1:B5,A1:A5,">="&x,A1:A5,"<"&x+1),CHOOSE({1,2},x,y))

Label giving the MAX result in an Index-Match lookup

I'm doing a table with the best outputs of an experiment. In this table I need to display the best (maximum) result for every combination of Sample and Method. And also the Test that gave this best result.
After checking similar questions here, I got how to do the first part (MAX result), but got no solution for the second part (label/test giving that result).
Here's a simplified table to see if you can help me to understand how to do that:
Data Table
A B C D E
1 Test1 Test2 Test3
2 Sample1 Method1 1.6 2.2 0.1
3 Sample2 Method1 1.5 1.3 0.6
4 Sample3 Method1 1 0 0.6
5 Sample1 Method2 0.5 0.1 1.7
6 Sample2 Method2 1.5 0.5 1
7 Sample3 Method2 0.4 0.5 2.7
8 Sample1 Method3 0.7 1.7 1
9 Sample2 Method3 1.1 1.1 1.2
10 Sample3 Method3 0.6 0.4 1.5
And here Is a draft of the table I hope to build
G H I J K L M
1 BEST Sample1 Sample1 Sample2 Sample2 Sample3 Sample3
2 RESULTS ValMax Test ValMax Test ValMax Test
3 Method1 2.2 1.5 1
4 Method2 1.7 1.5 2.7
5 Method3 1.7 1.2 1.5
As you can see I already get how to check which was the maximum value of each combination, thanks to this array function (at H3):
=MAX(IF(($A$2:$A$10=H1)*($B$2:$B$10=G3);$C$2:$E$10))
(and Control + Shift + Enter )
But for the second part I have no clue. I need to extract, from the "row 1", which of the 3 Tests (Test1, Test2 and Test3 at Columns C, D and E) contains the MAX value for the Row that contains the right combination of Sample and Method.
I tried with something like this (at I3):
=INDEX($A$1:$E$10; 1; MATCH(H3&H$1&G3; $C$2:$E$10&$A$2:$A$10&$B$2:$B$10;0))
(and Control + Shift + Enter )
But is obviously not working, because I'm mixing rows and columns.
How do I get the value from row 1 (Test) that corresponds with the Maximum value of the combination of Method and Sample?
Although I'd probably use VBA to construct the table, the following formula will return the Test that corresponds to the sample:
I3: =INDEX($C$1:$E$1,1,MATCH(H3,INDEX($C$2:$E$10,MATCH(TRUE,IF((I$1=$A$2:$A$10)*($G3=$B$2:$B$10),TRUE),0),0),0))
You will need to adjust addresses for the different columns, or combine this with your other formula in an IF function to decide whether to display the score or the test name.
Here is a non CSE Array formula that will do it:
=INDEX($C$1:$E$1,MAX(INDEX(($G3=$B$2:$B$10)*($A$2:$A$10=I$1)*($C$2:$E$10=H3)*(COLUMN($C$2:$E$10)-COLUMN($C$2:$C$2)+1),)))

Ignore #N/As in Excel LINEST function with multiple independent variables (known_x's)

I am trying to find the equation of a plane of best fit to a set of x,y,z data using the LINEST function. Some of the z data is missing, meaning that there are #N/As in the z column. For example:
A B C
(x) (y) (z)
1 1 1 5.1
2 2 1 5.4
3 3 1 5.7
4 1 2 #N/A
5 2 2 5.2
6 3 2 5.5
7 1 3 4.7
8 2 3 5
9 3 3 5.3
I would like to do =LINEST(C1:C9,A1:B9), but the #N/A causes this to return a value error.
I found a solution for a single independent variable (one column of known_x's, i.e. fitting a line to x,y data), but I have not been able to extend it for two independent variables (two known_x's columns, i.e. fitting a plane to x,y,z data). The solution I found is here: http://www.excelforum.com/excel-general/647448-linest-question.html, and the formula (slightly modified for my application) is:
=LINEST(
N(OFFSET(C1:C9,SMALL(IF(ISNUMBER(C1:C9),ROW(C1:C9)-ROW(C1)),
ROW(INDIRECT("1:"&COUNT(C1:C9)))),0,1)),
N(OFFSET(A1:A9,SMALL(IF(ISNUMBER(C1:C9),ROW(C1:C9)-ROW(C1)),
ROW(INDIRECT("1:"&COUNT(C1:C9)))),0,1)),
)
which is equivalent to =LINEST(C1:C9,A1:A9), ignoring the row containing the #N/A.
The formula from the posted link could probably be adapted but it is unwieldy. Least squares with missing data can be viewed as a regression with weight 1 for numeric values and weight 0 for non-numeric values. Based on this observation you could try this (with Ctrl+Shift+Enter in a 1x3 range):
=LINEST(IF(ISNUMBER(C1:C9),C1:C9,),IF(ISNUMBER(C1:C9),CHOOSE({1,2,3},1,A1:A9,B1:B9),),)
This gives the equation of the plane as z=-0.2x+0.3y+5 which can be checked against the results of using LINEST(C1:C8,A1:B8) with the error row removed.

Excel - allocate weight based on text

I have an risk control assessment where some controls are key and hold greater weight than non key controls.
Key vaule (1-4)
Y 4
Y 3
N 2
N 2
I want the keys with a "Y" to be summed at a weight of 70% and the non-keys with an "N" to be summed at a weight of 30%.
If we add the column we get 11. However, I want the 7 (4+3) to be multiplied by 70% and the 4 (2+2) be multiplied by 30%.
There may be 4 rows or 40. There generally are only 1 or 2 key controls ("Y"), but, if there are 40 rows or controls, there may be up to 5 "Y"s.
Any thoughts?
A simple way to do what I think you want would be to create a third column that had formulas like this one: =IF(A1="Y",B1*0.7,B1*0.3). Then, you could use the SUM function to add up all of the results. See the cells with formulas below.
Key Value Weighted Value
Y 1 =IF(A2="Y",B2*0.7,B2*0.3)
N 2 =IF(A3="Y",B3*0.7,B3*0.3)
N 3 =IF(A4="Y",B4*0.7,B4*0.3)
Y 4 =IF(A5="Y",B5*0.7,B5*0.3)
=SUM(C2:C5)
Here would be the result...
Key Value Weighted Value
Y 1 0.7
N 2 0.6
N 3 0.9
Y 4 2.8
5
As you can seen from #TimWilliams' comment, there is some uncertainty about your requirement but if it is weighting factors then the following formula might suit:
=IF(A2="Y",C$1*SUM(B:B)*B2/SUMIF(A:A,"=Y",B:B)/SUM(B:B),(1-C$1)*SUM(B:B)*B2/SUMIF(A:A,"=n",B:B)/SUM(B:B))
copied down to suit and assuming a layout as shown:

Resources