I have 10 different matrices, each matrices represents a region. For example: Canada, South West, Florida, etc. Within each matrix is a list of products in the rows and a list of products in the columns. All of the matrices have been created as tables in excel with the names being their region names. The values in the matrix represent the discount given to a customer if they purchase BOTH of those products in that region (The matrices are on a different tab from the lookup data). For example, in the matrix below, if a customer in Canada purchases Doll and Energy Drink, they will be given a $10 Discount.
How would you go about creating an equation in column D of the example below that returns that dollar value based on all three of these criteria: correct matrix, correct product (row), correct product (column). I do apologize for now posting an INDEX/MATCH equation to work from but I'm rather new to Excel and am not sure where to start. I will reply promptly to any questions you may have, Thanks!
Canada Matrix Example (Table Name = Canada)
Energy Drink Phone Bag
Doll $10 $20 $15
Hat $5 $13 $17
Stapler $8 $14 $23
Data Sheet
Column A Column B Column C Column D (Output)
Canada Doll Energy Drink Equation (=$10)
Florida Hat Phone Equation
South West Stapler Phone Equation
Canada Hat Notepad Equation (=$14)
The following INDEX/MATCH formula that will work within the single Canada array provided in the sample.
=INDEX($B$2:$D$4,MATCH($B9,$A$2:$A$4,0),MATCH($C9,$B$1:$D$1,0))
You could then copy this into several layers of IF statements which point each copy of the INDEX/MATCH formula to the appropriate Region array in the worksheet.
As long as Column B is always the Row, and Column C is always the Column, then this should work fine. In the case of the provided sample, the last transaction (Canada, Hat, Stapler, return 14) does not work because the reference array does not have a Stapler column. I assume the working file has a more expansive array.
This worked for me:
As long as your tables are named ranges it wouldn't matter where they're located.
I broke up the logic into a number of columns but you could just as easily combine them into a single formula.
The key is that:
INDEX(TableRangeHere, 1, 0)
INDEX(TableRangeHere, 0, 1)
return the entire first row and column respectively of the named range
In case anyone wants to see the answer I came up with. It involves a series of INDEX/CHOOSE/VLOOKUP/MATCH functions. The Regions are simply the names I gave the matrices
=INDEX(CHOOSE(VLOOKUP(B:B,xref!L:M,2,0),Canada[#All],Central[#All],Florida[#All],GreatLakes[#All],MidAtlantic[#All],NorthEast[#All],NorthWest[#All],SouthCentral[#All],SouthEast[#All],SouthWest[#All]),MATCH(F2,CHOOSE(VLOOKUP(B:B,xref!L:M,2,0),Canada[[#All],[MODEL]],Central[[#All],[MODEL]],Florida[[#All],[MODEL]],GreatLakes[[#All],[MODEL]],MidAtlantic[[#All],[MODEL]],NorthEast[[#All],[MODEL]],NorthWest[[#All],[MODEL]],SouthCentral[[#All],[MODEL]],SouthEast[[#All],[MODEL]],SouthWest[[#All],[MODEL]]),0),MATCH(E2,CHOOSE(VLOOKUP(B:B,xref!L:M,2,0),Canada[#Headers],Central[#Headers],Florida[#Headers],GreatLakes[#Headers],MidAtlantic[#Headers],NorthEast[#Headers],NorthWest[#Headers],SouthCentral[#Headers],SouthEast[#Headers],SouthWest[#Headers]),0))
Related
I am very very new to Excel
I have two sheets
Sheet 1
Country PMU Cluster
A Asia Mercury
B Australia Venus
C North America Jupiter
All the countries and continents are unique here
In sheet 2
I have
CountryCode Country PMU Cluster
123 A
234 A
453 B
235 C
1 country can have multiple codes
I have to take the PMU and Cluster and merge it with Sheet 2 , sheet 2 will have an additional column of Country Code.
Any help is very much apprciated.
Replacing my answer per your edits.
I'm just doing this on a single sheet but you can easily adapt by pointing to your other sheet for your lookup array.
Here is the formula for cell G2:
==VLOOKUP($F2,$A:$C,2,FALSE)
Here is the formula for cell H2:
=VLOOKUP($F2,$A:$C,3,FALSE)
Drag your formulas down and you're done. Vlookup formulas are very useful I recommend looking up how they work as someone else could better explain than I. Basically, you are looking up a value (column F) in an array (columns A,B,C) and returning a column index (B = 2, C = 3, etc) for a match. Lastly, you are looking for an approximate (TRUE) or exact (FALSE) match. Almost always use FALSE.
Also, look up cell references and how to lock them (ie, how $ signs rules vary). That way you can easily drag formulas across and keep your lookup value and array the same.
I'm trying to create a chart that finds the name of the first (then second, third, fourth, etc.) largest entry (via total sales) that meet certain criteria from a second Excel worksheet. (i.e. I want to find the largest sales value that is of the good "Apples" and sold in "Europe" if you will, as well as display the customer that this largest sales dollar amount was sold to.)
I've created some code that is giving me the name corresponding to the largest value on the sheet (very good!). However, this name does not meet the criteria in my if statement.
Example code: =INDEX('Sheet1'!B:B,MATCH(1,INDEX(('Sheet1'!V:V=LARGE(IF(AND('2. Sheet1'!E2:E1000="Apple", 'Sheet1'!W2:W1000="Europe"), 'Sheet1'!V:V, ""), ROWS(C$1:C1)))*(COUNTIF(C$1:C1,'Sheet1'!B:B)=0),),0))
B is the column with the customer name, V is the column with the overall sales amount, E is the column showing the name of the item sold, W is the name of the geographic area, C is the column (on the new sheet) where the name of the customer will be duplicated.
What I want to see is the customer who bought the most apples in Europe...but instead I'm getting the largest sales volume over all.
To make it stranger, if "apples" and "Europe" don't appear on the top row of Sheet1, I'm getting #N/A. (This does not happen, though, if these are contained in the top row.)
Does anyone have any thoughts as to how to fix?
In the following sample data image, the formulas in AB2:AC2 are:
=AGGREGATE(14, 6, (V$2:V$21)/((W$2:W$21=AA2)*(E$2:E$21=Z2)), COUNTIFS(Z$2:Z2, Z2, AA$2:AA2, AA2))
=INDEX(B:B, AGGREGATE(15, 6, ROW($2:$21)/((E$2:E$21=Z2)*(W$2:W$21=AA2)*(V$2:V$21=AB2)), COUNTIFS(Z$2:Z2, Z2, AA$2:AA2, AA2, AB$2:AB2, AB2)))
If you need to do it all in one formula, substitute the formula from AB2 (sans =) for every occurrence of AB2 within the formula from AC2.
Fill down as necessary.
I have a sheet of data with multiple dimensions like this:
A B C D E
1 COUNTRY FLAVOUR SIZE DATE SALES ($)
2 Japan Strawberry 100ml 10/12/14 100
3 Japan Banana 100ml 10/03/15 100
4 China Orange 200ml 14/04/15 30
5 France Strawberry 200ml 11/04/15 400
6 UK 200ml 23/04/15 250
7 ....
I want to aggregate this data over a date range, where the summary sheet has each dimension (country & flavour), and if I do not specify a dimension it sums all rows for that dimension.
A B C
1 COUNTRY FLAVOUR SALES TOTAL
2 Japan Strawberry 100
3 Japan 200
4 Strawberry 500
I can do this if all the dimensions are present (i.e. row 2 above) using a SUMPRODUCT or SUMIFS:
=SUMPRODUCT((data!A$2:A$100=A1)*(data!B$2:B$100=B1)*(data!D$2:D$100>[start_date]*(data!D$2:D$100<[end_date])*(data!E$2:E$100))
However I have not been able to figure out how to include all rows for a dimension if that input cell is empty (e.g. row 3 above). I tried:
Adding an IF statement or OR statement within the criteria (e.g. OR(data!A$2:A$100=A1,isblank(A1))).
Using a + in a SUMPRODUCT as an OR statement, (per this answer https://stackoverflow.com/a/27536131/1450420)
One solution is to have different branches of the formula depending on which summary dimensions are present, but that would quickly get out of control if I extend this same behaviour to further dimensions like Size.
Any help appreciated!
(I'm running Excel Mac 2011).
EDIT
Per #BrakNicku's comment one of the formulas I tried was =SUMPRODUCT(((data!A$2:A$100=A2)+ISBLANK(A2))*((data!B$2:B$100=B2)+ISBLANK(B2))*(data!E$2:E$100))
The reason this doesn't work is that sometimes my data has blank attributes (edited above). For some reason this formula double-counts rows where the attribute present matches (e.g. data!A6) but the other attribute is missing (e.g. data!B6).
EDIT 2
I can see why this double-counting is happening, because the + is summing the match because data!A$2:A$100=A2 (they match because they are both blank) and the match because ISBLANK(A2) (it is indeed blank). The question would remain how to achieve this without double counting. If needed a workaround could be to fill all blank cells on my data with some placeholder value.
The reason for double-counting values is here:
((data!A$2:A$100=A2)+ISBLANK(A2))
If a cell in A column is blank, both parts of this sum are equal 1. To get rid of this problem you can change it to:
(((data!A$2:A$100=A2)+ISBLANK(A2))>0)
Try this (I only included the first two, I left the dates out):
=SUMPRODUCT((((Data!$A$2:$A$5=A2)+(A2=""))>0)*(((Data!$B$2:$B$5=B2)+(B2=""))>0)*(Data!$E$2:$E$5))
I have a spreadsheet of sales with (to keep the example simple) 3 columns
NAME -- STATE -- COUNTRY
It's easy to find how many sales. (sum all the lines)
I can find out how many customers I have but how about finding out how many customers from a particular state (and country)
NAME -- STATE -- COUNTRY
p1----- CA------ USA
p2----- CA------ USA
p1----- CA------ USA
p1----- CA------ USA
p3----- NY------ USA
p3----- NY------ USA
The above example would give 2 unique customers from CA and 1 unique customer from NY and 3 from the USA
EDIT:
The desired result from the above table would be
STATE - UNIQUE CUSTOMERS
CA ---- 2
NY ---- 1
COUNTRY - UNIQUE CUSTOMERS
USA ---- 3
Assuming your data have headers in row 1 of columns A, B, and C, follow these directions.
In cell F1 enter STATE.
In cell G1 enter COUNT.
In cell F2 enter this array-formula (must be confirmed with Ctrl+Shift+Enter↵):
=IFERROR(INDEX(B$2:INDEX(B:B,COUNTA(B:B)),MATCH(0,COUNTIF(F$1:F1,B$2:INDEX(B:B,COUNTA(B:B))),)),"")
In cell G2 enter this regular formula (confirmed with Enter):
=IF(LEN(F2),COUNTIF(B2:B13,F2),"")
Select F2:G2 and copy.
Now select F3:F51 and paste.
UPDATE
The nature of the question changed. The first formula is exactly the same as before. It gets the distinct states in the source data and culls them so they display with no blanks.
The second formula is now different. It needs to count the number of distinct customers in each state, and it is now an array formula confirmed with Ctrl+Shift+Enter↵).
=IF(LEN(F2),SUM(IF(F2=$B$2:$B$50,1/(COUNTIFS($B$2:$B$50,F2,$A$2:$A$50,$A$2:$A$50)),)),"")
This formula (entered as an array formula CTRL-SHIFT-ENTER) will count the number of occurrences of a Name in MyState
=COUNTIFS(Names,Names,States,MyState)
So if MyState="CA" this would return {3;1;3;3;0;0}
To get the number of names in CA you can sum the reciprocals of this array, EXCEPT taking the reciprocal of zero is invalid/infinite. So wrap the formula above in a test for zero: if it's zero, output zero, otherwise take the reciprocal (one of the rare situations where you get to set infinity equal to zero!):
=IF(COUNTIFS(Names,Names,States,MyState)=0,0,1/COUNTIFS(Names,Names,States,MyState))
(Still an array formula.)
For CA this will return {0.333333;1;0.333333;0.333333;0;0}
The final step is to sum with the array formula:
=SUM(IF(COUNTIFS(Names,Names,States,MyState)=0,0,1/COUNTIFS(Names,Names,States,MyState)))
It's possible that this could return say 2.99999... instead of 3 due to rounding errors. If that's a problem you can fix it by wrapping it with the ROUND function or setting the display format zero decimal places.
It should be straightforward to modify this to count by country. Hope that helps.
Since the question also has an 'google-spreadsheets' tag, this would be my suggested formula to use in a google spreadsheet:
For the state counts:
=query(unique(ArrayFormula({A2:A&B2:B, A2:C})), "select Col3, count(Col1) where Col3 <> '' group by Col3 label count(Col1)''",0)
And for the country counts:
=query(unique(ArrayFormula({A2:A&B2:B&C2:C, C2:C})), "select Col2, count(Col1) where Col2 <> '' group by Col2 label count(Col1)''",0)
Also see this example spreadsheet.
Easy with a PivotTable in Excel 2013:
Also easy with Google Spreadsheets:
I have been searching for a way to make a "Top Ten" list for my uncles hockey league in Excel.
There are 5 different teams with their own worksheets and I made a separate worksheet called "data" referencing all of the players and their individual stats so that I could pull my "Top Ten" from one worksheet instead of five.
The worksheet is setup as follows:
Player1 Player2 Player3 etc...
Name
Team
Goals
Assists
Points
I would like to search for the player with the highest number of "Points" and return the name, team, goals, assists, and points on a single row, and then move down for the next player, i.e.:
Name 1 Team Goals Assists Points
Name 2 Team Goals Assists Points
I have tried using multiple ways including index and hlookup with the large and match commands, but could not get anything to work.
I feel like I am missing something simple here.
If it would be easier to have the players in rows, I could do that.
I was just having a problem with my references filling in the way I wanted them to.
Initial table:
B1: =COUNTA(B6:O6)(the number of players)
B6:O6 Name
B7:O7 Team
B8:O8 Goals
B9:O9 Assists
B10:O10 Points
Formulae below determine the rank for the player. If the score of points are equal, the player having a greater number of goals ranks higher.
B4: =$B$1-RANK(B$10;$B$10:$O$10)+B8/1000, the formula is copied to the right. The result will be fractional numbers with equal integer parts for the equal amount of points.
B3: =RANK(B4;$B$4:$O$4), the formula is copied to the right
B2: =IF(COUNTIF(C$3:$O$3;B3)>0;B3+COUNTIF(C$3:$O$3;B3);B$3)
Ranked table:
A15 and down : Rank (1,2...n)
B15 and down : =HLOOKUP(A15;$A$2:$O$3;2;FALSE)
In the next columns: Name (col C), Goals (col D), Assists (col E), Points (col F)
C15: =HLOOKUP($A15;$A$2:$O$10;5;FALSE)
D15: =HLOOKUP($A15;$A$2:$O$10;7;FALSE)
E15: =HLOOKUP($A15;$A$2:$O$10;8;FALSE)
F15: =HLOOKUP($A15;$A$2:$O$10;9;FALSE)
Formulae in B11:E11 will be copied down.
Example spreadsheet: http://www.bumpclub.ee/~jyri_r/Excel/Top_players_matrix_transposed.xls
you have to transpose the table first..
select all the rows and columns of your table.
right click the first cell where you want to paste the table
click paste special option
check the transpose check-box in the dialog-box opened.
your table is now transposed. now simple sorting can give u answer
for sorting columns :
select the whole table and click on the sort option on menu bar,
now you can retrieve all 10 top teams from this sorted list.