Finding value on a column based on another column and a parameter - excel

I have 3 columns like this:
+-----+----+-------+
| 50 | 10 | 20 |
| 175 | 30 | 17.14 |
| 150 | 25 | 16.66 |
| 250 | 40 | 16 |
| 100 | 15 | 15 |
+-----+----+-------+
What I want to achieve is when I type a value in a completely other box, I want to find the highest value in C column with the value closest (or equal to) among the ones lower than the value I entered.
For example if I write 56 I want 20 to come as a result or 16.66 for 160.
I don't know if I can parametrize the input (56 and 160 in the example above) in Excel. Would be visually better if I could light up the line for the correct value.
I'm sure this is doable in Excel to some extent but I don't know how.

You haven't explained the purpose of column B but based on your question the following would work:
Formula in F2:
=INDEX(C1:C5,MATCH(MIN(ABS(A1:A5-E2)),ABS(A1:A5-E2),0))
Note It's an array formula which need to be confirmed through CTRLSHIFTENTER
Without pressing CSE, you could use the following formula:
=INDEX(C1:C5,MATCH(MIN(INDEX(ABS(A1:A5-E2),)),INDEX(ABS(A1:A5-E2),),0))

Related

Excel formula to find a conditional minimum of visible cells only

At first I must to apologize if I did some translation mistakes of formula names. It will be hard to describe what I need because Polish Excel formula names are totally different than English ones and it is not possible to switch between languages and the names in Excel. But let's try...
I know solutions to find a conditional minimum using e.g. {=MIN(IF($A$2:$A$10=$A11;$B$2:$B$10;""))} array formula and to find a minimum of a filtered group of cells (minimum of visible cells only) using e.g. SUBTOTAL(105;$B$2:$B$10) or AGGREGATE(5;3;$B$2:$B$10) formulas but I can't find a way to merge both these solutions together to get the minimum of all visible cells meeting the condition.
In other words I need to get the minimum value of visible cells only in the range B2:B10, but only from rows where the value in the range A2:A10 is equal to a particular value in the cell A11 and the value in B2:B10 is greater then zero.
+---+-----+
| A | B |
+---+-----+
| 1 | 170 |
........... <== here some hidden (filtered or grouped) rows with other values
| 1 | 120 |
| 1 | 100 | <== minimum for "1"
| 1 | 0 | <== not included for "1" - only > 0
| 2 | 110 |
........... <== here some hidden (filtered or grouped) rows with other values
| 2 | 109 |
| 2 | 105 | <== minimum for "2"
| 3 | 50 | <== minimum for "3"
| 3 | 0 | <== not included for "3" - only > 0
+===+=====+
| 1 | 100 | <= expected results of formula - minimum values, greater then zero, for groups "1", "2" and "3"
| 2 | 105 |
| 3 | 50 |
+---+-----+
Kind regards - McVik
Use AGGREGATE(15,7,...), which allows array processing:
=AGGREGATE(15,7,$B$2:$B$10/(($A$2:$A$10=$F12)*($B$2:$B$10>0)*(SUBTOTAL(3,OFFSET($B$2,ROW($B$2:$B$10)-MIN(ROW($B$2:$B$10)),,1)))),1)
I helped myself temporary by adding a "technical" column (e.g. "C") with a simple formula in each cell
=SUBTOTAL(103,$B2)
=SUBTOTAL(103,$B3)
=SUBTOTAL(103,$B4)
... etc.
and the final array formulas check if the value in this column equals 1.
{=MIN(IF($A$2:$A$10=$A11,IF($B$2:$B$10>0,IF($C$2:$C$10=1,$B$2:$B$10,""),""),""))}
{=MIN(IF($A$2:$A$10=$A12,IF($B$2:$B$10>0,IF($C$2:$C$10=1,$B$2:$B$10,""),""),""))}
{=MIN(IF($A$2:$A$10=$A13,IF($B$2:$B$10>0,IF($C$2:$C$10=1,$B$2:$B$10,""),""),""))}
And now it works exactly as I expected.
PS. Excuse me for using semicolons in my examples. My Excel localisation requires semicolons instead of commas (as I see you use in English version).
Regards - McVik

Excel - Return most occurred value based on based on multiple condition

I have three main column Name, Size, and Diameter. What I want is to filter the name and return the most occurred value in Diameter for a particular value in Size. For example I have a table like below :
| Name | Size | Diameter |
------------------------------
| A | 30 | 2232.23 |
| A | 30 | 2232.23 |
| A | 30 | 5382.98 |
| A | 29 | 1123.44 |
| A | 29 | 9323.42 |
| A | 29 | 1123.44 |
| B | 31 | 1232.11 |
| B | 31 | 1232.11 |
| B | 10 | 1111.00 |
------------------------------
The value that I should be receiving from Diameter for A with the Size of 30 is 2232.23 while for B I should be receiving Diameter value of 1232.11 for Size 31
This is just a sample of it. The actual data is more than 9000+ row.
Thanks.
Considering your data is in column A,B,and C you can put this array formula in cell D1
=INDEX(C$1:C$10,MODE(IF(A$1:A$10=A1,MATCH(B$1:B$10,B$1:B$10,{0,0}))))
Don't forget to press Ctrl+Shift+Enter.
Try Paste in cell D2 and drag to the last row:
=COUNTIFS(A:A,A2,B:B,B2,C:C,C2)
It returns the number of occurrences each row.
Use this formula. Formula first creates array of values that pass 2 set conditions. then IF formula removes 0 values from an array. Lastly MODE formula evaluates remained values and return the one with most occurrences.
=SUMPRODUCT(IFERROR(MODE(IF(--($A$3:$A$11000=G2)*($B$3:$B$11000=H2)*$C$3:$C$11000<>0,--($A$3:$A$11000=G2)*($B$3:$B$11000=H2)*$C$3:$C$11000,"")),MAX(--($A$3:$A$11000=G2)*($B$3:$B$11000=H2)*$C$3:$C$11000)))
Enter it using CTRL+Shift+Enter, since it is an array formula.
if you want to show most occurrences in ColumnD then use this formula in cell D3 and drag it to the bottom.
=SUMPRODUCT(IFERROR(MODE(IF(--($A$3:$A$11000=A3)*($B$3:$B$11000=B3)*$C$3:$C$11000<>0,--($A$3:$A$11000=A3)*($B$3:$B$11000=B3)*$C$3:$C$11000,"")),MAX(--($A$3:$A$11000=A3)*($B$3:$B$11000=B3)*$C$3:$C$11000)))
Here is an array formula (click Ctrl + Shift + Enter together) you can try:
=INDEX($C$2:$C$20,MATCH(MODE(IF(($A$2:$A$20=E2)*($B$2:$B$20=F2)*($C$2:$C$20),($A$2:$A$20=E2)*($B$2:$B$20=F2)*($C$2:$C$20),"")),$C$2:$C$20,0),1)
Basically it is using MODE function to find the most frequent occurance and then use INDEX/MATCH to return the value.

How to return the header by value in a PivotTable

I have a PivotTable like this:
Sum of Gf_Amount | Column Labels
| 2015 | | | | Grand Total
Row Labels | 17-Mar | 18-Mar | 19-Mar | 20-Mar |
3601 | 20 | 20 | | | 40
10386 | 35 | | | | 35
76301 | 5 | | | | 5
80941 | | | | 10 | 10
205738 | | | 5 | | 5
219576 | | 15 | | | 15
Grand Total | 60 | 35 | 5 | 10 | 110
What I want do is find the last non-empty column and return the date according to the value. For example: for ID 3601 the result should be 2015 18-Mar.
Currently I know how to find the last non-empty column by using =LOOKUP(9.99E+307,B6:E6). For ID 3601 it gives me 20 which is correct. However when I use:
=INDEX($B$5:$E$5,MATCH(LOOKUP(9.99E+307,B6:E6),B6:E6,0))
to find the header, it gives me 17-Mar which is the corresponding header for the first 20. Besides, the formula I wrote can't even give me the year.
Can anyone help me out so I can find the date and year? (It doesn't have to be in PivotTable. You can copy and paste it in a normal table.)
I'm guessing that your column labels are date indices formatted as dd-mmm so there is no need to find the 2015 that is displayed hence:
=INDEX($5:$5,MATCH(1E+100,A6:E6))
formatted as say dd-mmm-yyyy and presumably copied down may suit.
It is a peculiarity (perhaps never really intended) of the MATCH function that, without the optional argument, where it can’t find a match in a list it returns the index of the last entry in the list – very useful, as here, at times! So all the “big number” (there are lots of versions of it – for example the one you used 9.99E+307) does is feed MATCH a number so large it is never likely to find it (to force selection of the last entry).
I like 1E+100, a googol, as short and easy to remember, and for its ‘derivation’. 9.99E+307 is theoretically better as closer to the largest number Excel can handle:
9.99999999999999E+307
but
10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
for me is big enough – I don’t expect ever to want to work with a number bigger than that and smaller than or equal to 9.99E+307.

Counting the frequency of combinations of numbers (in excel using VBA)

I want excel to count the FREQUENCY that certain number-letter combinations appear down a column in excel (using vba). All my data goes down one column like this:
Column A (only 1,2,3,4,5,s,f appear)
1
2
s
4
3
s
4
2
f
2
s
2
s
I want to count the number of occasions combinations of (1-s, 2-s, 3-s, 4-s, 5-s) occur, strictly when the number occurs first (is in the higher row). I do not want to count occasions when the s comes before the number (e.g. s-2). I know how to count the number of individual letters/numbers using the countIf function.
I might later want to expand my analysis to look at the occasions that three letter-number combinations (e.g. 2-s-3, 2-s-5)
I am very much a VBA noob.
Try inserting a new column to the right of Column A. Use this formula =A1&A2 and fill it down the column. The values will look like this:
+----------+----------+
| Column A | Column B |
+----------+----------+
| 1 | 12 |
| 2 | 2s |
| s | s4 |
| 4 | 43 |
| 3 | 3s |
| s | s4 |
| 4 | 42 |
| 2 | 2f |
| f | f2 |
| 2 | 2s |
| s | s2 |
| 2 | 2s |
| s | s |
+----------+----------+
Now you can count occurences like you were doing before! :D
Of course, you can expand to three character frequency analysis by making the formula =A1&A2&A3.
Seems possible with COUNTIFS, with 1 to 5 inclusive in C1:G1 and in C2:
=COUNTIFS($A1:$A12,C1,$A2:$A13,"s")
copied across to suit.
You can use the VBA equivalent of this formula
=SUMPRODUCT(--(ISNUMBER(A1:A12)),--(A2:A13="s"))
which looks for number, followed by s in the row below (4 for your sample)
code
MsgBox Evaluate("SUMPRODUCT(--(ISNUMBER(A1:A12)),--(A2:A13=""s""))")

Average of multiple survey responses (columns)

I feel a bit embarrassed for asking this but here goes:
I'm using Excel 2010 and I have a worksheet containing 700+ customer satisfaction survey responses. Each row is a survey with a 1-5 or NA response to 5 questions. It looks like the following:
+-Agent--+--Q1--+--Q2--+--Q3--+
| | | | |
| Jeff | 5 | 5 | 5 |
+--------+------+------+------+
| James | 1 | 1 | 1 |
+--------+------+------+------+
| Jack | 5 | 5 | 5 |
+--------+------+------+------+
| Jeff | 3 | NA | 5 |
+--------+------+------+------+
| Jeff | NA | NA | 3 |
+--------+------+------+------+
| James | 5 | 5 | 5 |
+--------+------+------+------+
| ... | ... | ... | ... |
+--------+------+------+------+
I want to create a worksheet listing each agent in column A and the average of all of questions answered regarding them. I tried a formula like AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:D7) where A2 contains the agent's name, but it doesn't appear to work properly.
For example, I get a 5.00 average for some agents when it should be a 4.61. When I look in the Function Arguments screen for my AVERAGEIF on this person, it looks like it recognizes the values properly. The Average_rage shows {"NA","NA","NA","NA",1;5,5,5,5,5;5,... but the returned value below that says = 5 which is not right since there is a 1.
Can anyone guide me in the right direction?
AVERAGEIF works like SUMIF, the second range used is actually the same size and shape as the first range, starting with the top left cell, so when you use this
=AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:D7)
because the first range is a single column then the second range used must be too (there's a 1 to 1 relationship between the cells) so because the top left cell in SurveyResponses!B2:D7 is SurveyResponses!B2 the range begins there and is the same size and shape as SurveyResponses!A2:A7
....so you are actually getting this....
=AVERAGEIF(SurveyResponses!A2:A7,A2,SurveyResponses!B2:B7)
AVERAGEIF help does tell you that but it isn't very clear
If you want the ranges to be different sizes you need an "array formula" like this
=AVERAGE(IF(SurveyResponses!A2:A7=A2,SurveyResponses!B2:D7))
You need to confirm that with CTRL+SHIFT+ENTER so that curly braces appear around the formula in the formula bar. That formula will count any blanks as zeroes but ignore text values like NA
Easiest way to do this would be a pivot table. They look scary, but they're fairly easy to use. Rows = names, Columns = Q, Average for the answers.

Resources