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),)))
Related
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))
it's been a while since I coded much in VBA so getting myself tangled in the loops.
I have a table (B3:E14) which I want to loop through to return all permutations, placing them one by one in the final column ("Test"), where I'll run some other code, then transpose that test column into a row of results with variables as columns.
Variable
Min
Max
Test
Apples
5
6
i
Bananas
2.5
3.5
j
Oranges
-2
-1
k
Does that make sense?
So my final table might look something like...
Run
Apples
Bananas
Oranges
etc
1
5
2.5
-2
2
6
2.5
-2
3
5
3.5
-2
4
5
2.5
-1
etc
2048
6
3.5
-1
Darren
Yes, it is possible to do that.
You should check out this article, about different loops in VBA, you'll get your answers here.
https://trumpexcel.com/vba-loops/
Here you can find some examples about looping through a table.
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))
I have two different series of data that look something like this
A B
1 0.998
2 0.9975
3 0.997
4 0.9967
5 0.9962
6 0.9960
.
.
.
and
C D
1 240.5
1.3 249.5
1.7 241.45
2 239.0
2.5 124.5
3 125.6
3.4 235.1
3.5 236.4
.
.
.
How can I merge the two in excel so that the end results will look like this?
C C E
1 240.5 0.998
1.3 249.5 0.998
1.7 241.45 0.998
2 239.0 0.9975
2.5 124.5 0.9975
3 125.6 0.997
3.4 235.1 0.997
3.5 236.4 0.997
Essentially I need to add, for each integer of the column C, its corresponding value as shown in the series A,B. the whole dataset is 3500 rows long, so I am looking for an automated solution that can help me with that before I resolve to painstakingly paste each value in its position.
In column E you can create a formula that uses your first table (A/B) as a LOOKUP table. Truncate the value in Column C as your lookup value.
So in column E, use a formula something like,
=LOOKUP(TRUNC(Cx), A1:An, B1:Bn)
where x is the row number of your C/D/E table, and n is the last row in your A/B table.
Suppose I have the following data
Name Output
A 0.1
B 7
C 0.4
D 0.9
E 1.1
F 12
G 22
I would like replace the output variable by custom ranges:
Name Output Output_2
A 0.1 0m-0.3m
B 7 6y-10y
C 0.4 0.4m-0.6m
D 0.9 0.7m-1y
E 1.1 1y-5y
F 12 11y-20y
G 22 21y-40y
Right now, I am doing this (a long list of nested IFs)
=IF([#Tenor]<= 0.25, "0m-3m", IF([#Tenor]<=0.5, "4m-6m", IF([#Tenor] <= 1, "7m-1y",IF([#Tenor]<=5,"2y-5y",IF([#Tenor]<=10,"6y-10y",IF([#Tenor]<20,"11y-20y",IF([#Tenor]<40,"20y-40y")))))))
and it works but I am concerned that as the number of ranges increases, this will be painful to write. I was hoping I could write down a range somewhere and ask excel to look it up and do some case type thing.
Let's assume your first three columns are A, B and C (like in the second code block you posted). Add the following data into columns E and F (this will be your mapping data):
Output Output2
0 0m-3m
0.25 4m-6m
0.5 7m-1Y
1 2y-5y
5 6y-10y
10 11y-20y
20 20y-40y
40 20y-40y
Then write the following formula into C2 cell and drag it down:
=INDEX($F:$F,MATCH(B2,$E:$E,1))
UPDATE: you can do this even simpler with approximate VLOOKUP:
=VLOOKUP(B2,$E:$F,2,1)