I am trying to create a dashboard that will find the largest ten values based on data in column D and display the contents of column C while excluding from the selection any row that contains a specific value in column B.
I am currently using =INDEX($C$1:$C$100,MATCH(LARGE($D$1:$D$100,1),$D$1:$D$100,0)) to find the largest value in D and display C.
I can't figure out how to exclude from the LARGE call any rows that have SKIPME in column B.
You can use an IF statement to do that:
=INDEX($C$1:$C$100,MATCH(LARGE(IF($B$1:$B$100<>"SKIPME",$D$1:$D$100),1),$D$1:$D$100,0))
Except that it also converts the formula into an array equation, so that you now have to press Ctrl+Shift+Enter to make it work.
You can also use this equivalent function, also called with CSE but slightly shorter:
=INDEX($C$1:$C$100,MATCH(LARGE(($B$1:$B$100<>"SKIPME")*$D$1:$D$100,1),$D$1:$D$100,0))
Or if you're only looking for the biggest value, then MAX works just as well:
=INDEX($C$1:$C$100,MATCH(MAX(($B$1:$B$100<>"SKIPME")*$D$1:$D$100),$D$1:$D$100,0))
In order to avoid problems with duplicate values in column D you can use this setup:
In F2 down to F11 list the values 1 to 11
In G2 use this formula confirmed with CTRL+SHIFT+ENTER and copied down to get the associated values from column D
=IFERROR(LARGE(IF(B$2:B$100<>"SKIPME",IF(D$2:D$100<>"",D$2:D$100)),F2),"")
then to get the column C items for the top 10 values use this formula in H2 confirmed with CTRL+SHIFT+ENTER and copied down
=IF(G2="","",INDEX(C$2:C$100,SMALL(IF(B$2:B$100<>"SKIPME",IF(D$2:D$100=G2,ROW(D$2:D$100)-ROW(D$2)+1)),COUNTIF(G$2:G2,G2))))
If there are fewer than 10 qualifying values you get blanks - see example here
Related
Having A1+C1 and B1+D1 in two cells how can I dynamically set up a formula to catch if some column is added.
Let's say the user adds two columns in the middle. I should have A1+C1+E1 and B1+D1+F1.
I thought it would have been automatic but it is not.
Replace:
=A1+C1
By:
=SUM(A1:C1) - B1
In case you want to check if the column number is divisble by three, you can use following formula:
=IF(MOD(COLUMN(A1);3)=0;A1;0) // I've put the values from 1 to 10 in A1-J1
// and I've dragged this formula from A2 to J2,
// the values were 0,0,3,0,0,6,0,0,9,0.
Unfortunately I don't have a simple way to sum those values in one easy formula.
If you always add two columns then A1+C1 will always be looking at odd number columns and B1+D1 will always be looking at even numbered columns.
{=SUM(IF(ISODD(COLUMN($A$1:$D$1)),$A$1:$D$1))}
and
{=SUM(IF(ISEVEN(COLUMN($A$1:$D$1)),$A$1:$D$1))}
As long as you insert columns between A:D the ranges will extend to accommodate.
Edit:
Based on the comment that row 2 contains codes and row 3 contains the figures to add up for each code then this array formula will work:
{=SUM(IF($A$2:$J$2="H1",$A$3:$J$3))}
Edit2: and if I wake up you can even use the non-array and built in formula:
=SUMIF($A$2:$J$2,"H1",$A$3:$J$3)
The H1 text can be changed to another code or to a cell reference containing the code to get the sum of values in row 3 for the specified code.
As an array formula it must be entered using Ctrl+Shift+Enter.
I have an Excel spreadsheet of the form:
A,B
X,1
X,5
Y,4
Y,11
X,7
Z,1
I would like to get the maximum value of column B for each distinct value of column A - how can I do it via pure Excel formula?
Desired result (order is irrelevant):
A,B
Y,11
X,7
Z,1
In other words, I would like Excel's version of an SQL query
SELECT A,max(B)
FROM myTable
GROUP BY A
Any version of Excel is acceptable, but I use 365 one.
Pivot tables are an acceptable approach (I currently did it with a pivot myself) but I would strongly prefer a real formula - the main goal of the question is to enhance my understanding of formula programming in Excel. No VBA
Gary's Student's answer is correct. I added a couple things.
Also, a link to the method:
http://blog.contextures.com/archives/2011/07/27/finding-min-if-or-max-if-in-excel/
A distinct list of values can be generated in a couple ways, here's one:
And here's links to a method or two for distinct lists. All with array formulas:
Ignore Duplicates and Create New List of Unique Values in Excel
Getting unique values in Excel by using formulas only
With data in columns A and B use the Array Formula:
=MAX(IF(A1:A6="x",B1:B6))
Same for "y" and "z"
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
Notice the braces in the Formula Bar
EDIT#1:
To generate the formulas automatically, first copy column A to column C.
Then use the Remove Duplicate feature in the Data tab:
Then enter the Array Formula in cell D1:
=MAX(IF(A$1:A$14=C1,B$1:B$14))
and copy down:
The formula is only entered once and then copied down!
Pivot table is the correct answer.
Select column A's title and drag it to the Row Labels section.
Select column B's title and drag it to the Values section.
Click the arrow on column B's title in the values section and choose Value Field Settings.
Select Max
Try below. Note I moved your desired output table to Columns D and E. You will not need to hard-code any values into formulas.
Data
D E
Y 11
X 7
Z 1
Formulas
E2 Formula: ={MAX(--($D1=A1:A6)*B1:B6)}
E3 Formula: ={MAX(--($D2=A2:A7)*B2:B7)}
E4 Formula: ={MAX(--($D3=A3:A8)*B3:B8)}
I have a lookup table like so:
a b c d
1 2 3 4
and a row filled with values a, b, c or d, for example:
d b b d c
I would like to get the minimum value after doing the lookup with the table in a single formula. Something like MIN(HLOOKUP(...)). In the example above, the result would be 2.
I know that I could create a new row with the HLOOKUP and later do a MIN on this row. But in my real case, I have several rows and several lookup tables and I would like to avoid having many intermediate rows.
Do you have any idea?
If your lookup array is named LetterValues and your data is in A1:E1 please try:
=HLOOKUP(CHAR(MIN(CODE(A1:E1))),LetterValues,2,0)
entered with Ctrl+Shift+Enter.
If you're data starts in cell A1, you can use the following array formula.
=MIN(IF(A1:E1="b",A2:E2,""))
It basically looks at the range A1:E1 and checks if it equals b. If it does, the formula stores the value from the row below, if not, it stores nothing.
Now that you have an array of all of the numbers associated with b, the MIN functions returns the smallest.
After typing in the formula, use Ctrl+Shift+Enter and curly brackets will appear around the formula.
Col A Col B
Fruit Grapes
Fruit Mango
Fruit Mango
Veg Carrot
Veg Brinjal
Fruit Banana
Veg Carrot
I have a similar requirement as shown in this thread
set drop-down values based on vlookup
This works fine, however now the requirement for me is in Column B there will be duplicates and the dropdown has to show only distinct values. Can any one help me with this
See file here Requirement
I want to achieve this by pure Excel formulas and not by VBA code.
Part 1 - This just shows how to create a unique list in a drop-down.
Here's a screenshot, but currently it requires that there is a row above the data(?). This provides a unique list of items in a Data Validation drop-down. (All the formulas below can be made easier to create by naming some ranges beforehand.)
The array formula in E2 is shown in the comment. Use Ctrl-Shift-Enter to enter an array formula, then drag this down as far as necessary - the #N/As will begin to appear at the bottom.
Gosh, it's hard to describe :). The COUNTIF essentially generates a sequence of 1s and 0s to indicate whereabouts in column B the previous (above) values in column E are positioned in column B. This sequence always starts with a 0 (for the formula in E2) because it's looking for a blank which doesn't occur in column B - so this will grab the first item, Grapes.
The MATCH then finds the first 0 in this sequence of 0s and 1s, which indicates that a value (in column B) hasn't already appeared in column E.
INDEX then uses this MATCHed value to retrieve the new unique item from column B.
Then a Defined Name is created (on the Formulas tab) that gets all the values in column E, but only down to the first occurrence of '#', which indicates there are no more unique values in the list.
This Defined Name is then used in the Data Validation.
Part 2 - The Answer (with VBA)
The following VBA code is required so that clicking in a cell in C11:C18 will change the value in F1, which generates the unique list underneath, which populates the data-validation list in C11:C18.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("C11:C18")) Is Nothing Then
Sheets("Sheet1").Range("F1").Value = ActiveCell.Offset(0, -1).Value
End If
End Sub
It requires the formulas and defined-name as shown in the following screenshot. The formula in F2 is different to F3, which is then copied down.
The number 10 in the formula in F3 is just a large number (of rows).
Column E are the unique items.
Column D are the corresponding categories.
Column F are the unique items for the category in cell F1 (extracted form column E).
Part 3 - Without VBA
Use the formula =INDIRECT(ADDRESS(CELL("row"),CELL("col")-1)) in cell F1. When you click into a cell in C11:C18 you need to press F9 to recalculate the worksheet, which updates the drop-down list.
Recalculating is necessary to update the CELL("row") and CELL("col") values.
Part 4 - Without pressing F9
It can be achieved without having to press F9, but it means spreading all the categories across different columns (G1 and to the right in the below screenshot). This can also be achieved with the array formula =INDEX($A$2:$A$8,MATCH(0,COUNTIF($F$1:F1,$A$2:$A$8),0)) in G1.
The #N/As can also be removed the the drop-down lists with strategic use of IFERROR() in the formulas from G2 onwards, substituting "". Alternatively, using:
=OFFSET(Sheet1!$G$1,1,MATCH(Sheet1!B11,Sheet1!$G$1:$J$1,0)-1,MATCH("#",OFFSET(Sheet1!$G$1,1,MATCH(Sheet1!B11,Sheet1!$G$1:$J$1,0)-1,COUNTA(Sheet1!$G:$G)-1,1),-1),1)
as the defined-name Items would not only remove the #N/As but also the redundant ("") values that IFERROR() would leave in the drop-down lists. (The cursor needs to be positioned in C11 when creating this defined-name.)
Apologies for the length of this, but hope it is of interest to someone.
I have tried finding this solution on the web but have not had success for this specific problem. In Excel 2010 I have some data in column A where each value may partially contain data in column B.
EX:
Column A might contain "http://google.com/webmasters"
Column B might contain "google.com"
This should give me a match.
I want to print in Column C all values in column A that do not contain any values from column B.
EX:
Column A
http://dir.mydomain.tdl
http://myotherdomain.tdl
http://blog.otherdomain.tdl
http://www.lastdomain.tdl
Column B
mydomain.tdl
lastdomain.tdl
Column C (results required)
http://myotherdomain.tdl
http://blog.otherdomain.tdl
Any help would be greatly appreciated.
I think I have the solution using ARRAY formula. Assuming your input AND that columns A-C have titles, or simply, strings are listed starting cells A2 and B2, do the following:
C2: type the formula =IF(OR(NOT(ISERROR(SEARCH(INDIRECT("B2:B"&(COUNTA($B:$B))),$A2)))),"",$A2) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
Autofill formula in C2 until the end of list in column A, e.g. if the last value is in A100, then autofill up to C100 (how long column B does not matter here).
You may then copy & paste obtained results as values and sort out empty strings.
Here you go! The key here - we check every string in column A for having at least one match among array of strings in column B, and return empty string in case at least one match found.
For your convenience sample file is shared: https://www.dropbox.com/s/janf0xxon4z2yh5/DomainsLookup.xlsx
Maybe not the must efficient but you could simply use two arrays - one for Column A and one for Column B. Iterate through ColumnA array to see if it exists in ColumnB array (use Array.IndexOf or .contains). If it does you could remove it from the ColumnA array and output the remaining values in Column C as the remainder.