Excel formula to find a conditional minimum of visible cells only - excel

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

Related

Spreadsheet Formula to Sum Values Over A if B is not in a List of Values

I have a table that looks the following:
| A | B | C |
| 40 | 1 | 1 |
| 180 | 2 | 2 |
| 34 | 1 |
| 2345 | 3 |
| 23 | 1 |
| 1 | 2 |
| 4354 | 3 |
| 2 | 2 |
| 343 | 4 |
| 2 | 2 |
| 45 | 1 |
| 23 | 1 |
| 4556 | 3 |
I want to get the sum of all fields in A where B is neither 1 nor 2 or any other value from colum C. This column contains the values of B where values from A should not be considered for the sum.
I do not know which values B might contain, those values are random and could grow larger, I just wanted to make the example small. My current solution is
{=SUMIF(B1:B13,C1:C2,A1:A13)}
so i can set the lines that should be excluded from the sum in column C. Unfortunately, the current solution does not solve my problem but something different -- it sums up the corresponding entries by value in C. My preferred solution would look something like
=SUMIF(B1:B13,"<>{1, 2}",A1:A13)
=SUMIF(B1:B13,"<>"&C1:C2,A1:A13)
if that were possible (it isn't). I would like to have:
a field (with a list, for example) or column where i can put in the values of B that I do not want to be part of the sum over A.
a method that works with Open Office as well as Excel. I prefer an OO solution.
You could use an array formula so that you can multiply each value in A with a condition. That condition can be any valid Excel formula, so, for instance, you could use MATCH to test if the B value occurs in C:
=SUM((A1:A13)*ISNA(MATCH(B1:B13,$C:$C,0)))
The ISNA function returns TRUE when the match fails, which in a multiplication is used as a numerical value 1. FALSE will make the product 0.
Make sure to enter this as an array formula with Ctrl+Shift+Enter

How to compare multiple HLOOKUP cases

In my sheet I have a formula using HLOOKUP to calculate a number based on the content of a cell. The content can be choosen among "OK","NOK","-".
Deliverable | CASE |Description | Value
Deliverable1 | OK | ******* | 3
Deliverable1 | NOK | ####### | 6
Deliverable1 | - | &&&&&&& | 10
Deliverable2 | OK | ******* | 4
Deliverable2 | NOK | ####### | 7
Deliverable2 | - | &&&&&&& | 9
I want then to calculate, for a given deliverable, the difference between the applied case and the case when the selection is put to "OK". I.e. if I have a -, I want to get 7.
To achieve this I have created a duplicate sheet where I force the content of the cell to be OK, and then I calculate the difference. The problem with this approach is that when using filtering or sorting the calculation is messed up.
Is there a way to avoid using the duplicate sheet?

Return array of all matches between two ranges

Ok so I am trying to take a common tutorial array formula a step further but cannot figure out how.
Essentially I have a set of sheets with values like below:
| Sheet 1 || Sheet 2 |
| Products(1) | Product Group || Products(2) | Data |
| | || | |
| 100 | 1 || 100 | abc |
| 200 | 2 || 200 | def |
| 300 | 3 || 200 | ghi |
| 400 | 3 || 500 | jkl |
| 500 | 2 || 400 | mno |
Sheet 1 lists all parameters that classify each product and uses those to assign each product to a group. Essentially Products is a unique index key.
Sheet 2 is a tracking list of every time that a product is run, how it did. Therefore product numbers may show up multiple times or not at all.
I have a third sheet in which a product number is entered, from that its group number is calculated, and sheet 1 is searched for all products with that group number and the list is returned using an array formula (using this tutorial http://thinketg.com/how-to-return-multiple-match-values-in-excel-using-index-match-or-vlookup/ which shows up all over on line by different people). We will call this "Column K" on Sheet 3.
What I want to do now is take it a step further and return "Data" from Sheet 2 for all matches between "Sheet 2"!"Products(2)" and "Sheet 3"!"Column K". If "Column K" was fixed I could use the same formula again and put an OR statement into the IF expression, but because K is dynamically populated I am not sure how to find them all.
For clarification, The end result that I would ideally show is like this:
| Sheet 3 |
| Product Num | Column K | Column L | Column M |
| (user enters) | (automatic) | (automatic) | (automatic) |
| 500 | 200 | 200 | def |
| | 500 | 200 | ghi |
| Product Group | | 500 | jkl |
| (automatic) | | | |
| 2 | | | |
If you compare a column vector with an row vector in an array formula then it will compare each value from the column with each value in the row. So the following will work because we transpose the values in Sheet3!K1:K[n] into a row vector before comparing with Sheet2!$A$1:$A$10000.
Sheet1:
Sheet2:
Sheet3:
Formulas in Sheet3:
In A5:
=VLOOKUP($A$2,Sheet1!$A:$B,2,FALSE)
In K2 downwards:
{=IFERROR(INDEX(Sheet1!$A$1:$A$10000,SMALL(IF(Sheet1!$B$1:$B$10000=$A$5,ROW(Sheet1!$B$1:$B$10000)),ROW(1:1))),"")}
In L2 downwards:
{=INDEX(Sheet2!$A$1:$A$10000,SMALL(IF(Sheet2!$A$1:$A$10000=TRANSPOSE($K$1:INDEX($K:$K,MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000))))),ROW(Sheet2!$A$1:$A$10000)),ROW(1:1)))}
In M2 downwards:
{=INDEX(Sheet2!$B$1:$B$10000,SMALL(IF(Sheet2!$A$1:$A$10000=TRANSPOSE($K$1:INDEX($K:$K,MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000))))),ROW(Sheet2!$A$1:$A$10000)),ROW(1:1)))}
Formulas in K2,L2,M2 are array formulas. Input them without the curly brackets and then press [Ctrl]+[Shift]+[Enter].
The reference to K[n] in Sheet3!K1:K[n] is computed with
INDEX($K:$K,MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000))))
therein the
MAX(IF($K$1:$K$10000<>"",ROW($K$1:$K$10000)))
gets the largest row number in column K where the content not equals "".
If the product numbers are ever numeric, then it is easier and it will be possible to have the results sorted also.
Sheet1 and sheet2 see above.
Sheet3:
Formulas in Sheet3:
In A5: see above
In K2 downwards:
{=IFERROR(SMALL(IF(Sheet1!$B$2:$B$10000=$A$5,Sheet1!$A$2:$A$10000),ROW(1:1)),"")}
In L2 downwards:
{=SMALL(IF(Sheet2!$A$2:$A$10000=TRANSPOSE($K$2:INDEX($K:$K,MATCH(MAX($K:$K),$K:$K))),Sheet2!$A$2:$A$10000),ROW(1:1))}
In M2 downwards:
{=INDEX(Sheet2!$B$1:$B$10000,SMALL(IF(Sheet2!$A$1:$A$10000=$L2,ROW(Sheet2!$A$1:$A$10000)),COUNTIF($L$2:$L2,L2)))}

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

Using a number in a cell to generate a cell reference

What I want to do might be better achieved with a database, however I have very limited experience with them, and only have to change the information infrequently.
What I have is a sheet where each row has 8 cells of relevant data.
What I want to do in another sheet is to enter a number into 1 cell, and have a group of cells below use that number to reference data in the other sheet.
For example, in Sheet1 I could have the following (fig 1):
| A | B | C | D | E | F | G | H
-----+-----+-----+-----+-----+-----+-----+-----+-----
101 | Dep | 700 | Sta | 100 | Sta | 300 | Dep | 900
What I want to achieve in sheet 2, by typing the row number into 1 cell, is to have the data in those 8 cells copied below, for example (fig 2):
| A | B | C | D |
-----+-----+-----+-----+-----+
1 | "Row Number" |
-----+-----+-----+-----+-----+
2 | =A# | =B# | =D# | =C# |
-----+-----+-----+-----+-----+
3 | =E# | =F# | =H# | =G# |
-----+-----+-----+-----+-----+
And yes, I am aware those formulae above do not reference the other sheet - this was to save space.
Which, if using the example row above, should look like this (fig 3):
| A | B | C | D |
-----+-----+-----+-----+-----+
1 | 101 |
-----+-----+-----+-----+-----+
2 | Dep | 700 | 100 | Sta |
-----+-----+-----+-----+-----+
3 | Sta | 300 | 900 | Dep |
-----+-----+-----+-----+-----+
So, in that example above (fig 3), what do I need to put in as a formula in cells A2-D2 & A3-D3 to automatically use the number in A1 as part of the cell reference to print the data from the other sheet.
Does that make sense? I hope so because I have over 300 lines to enter into my 1st sheet and another 70 lines x 7 blocks of columns on the second sheet.
Lastly I just want to say I want to avoid programming languages, like VBA, wherever possible.
Check out the INDIRECT() function.
For cell A2 in your example on the second sheet, enter:
=INDIRECT("Sheet1!"&"A"&$A$1)
Expand this formula to the apply to other target cells by changing the "&"A" portion to reference columns B, C, D, etc. from Sheet1 as needed in your grid per the following example:
=INDIRECT("Sheet1!"&"B"&$A$1)
=INDIRECT("Sheet1!"&"C"&$A$1)
=INDIRECT("Sheet1!"&"D"&$A$1)
These formulas will reference your selected "Row Number" in cell A1 and pull the related data from Sheet1 into Sheet2.
You can do this using the INDIRECT function
Returns the reference specified by a text string.
References are immediately evaluated to display their contents.
Use INDIRECT when you want to change the reference to a cell within a
formula without changing the formula itself.
http://office.microsoft.com/en-gb/excel-help/indirect-HP005209139.aspx

Resources