I have searched and searched and searched and searched, I can only find solutions for index/match with two criteria.
does anyone have a solution for index/match with three criteria?
as a sample of my actual data, i would like to index/match the year, type and name to find the data in the month column
You can match an unlimited number of criteria by using SUMPRODUCT() to find the proper row:
=INDEX(D2:D9,SUMPRODUCT((A2:A9=2015)*(B2:B9="Revenue")*(C2:C9="Name 1")*ROW(2:9))-1)
EDIT#1:
Scott's comment is correct! The advantagesof the SUMPRODUCT() approach is that it is not an array formula and can be expanded to handle many criteria. The disadvantage is that it will only work if there is 1 matching row. The use of SUMPRODUCT() is explained very well here:
xlDynamic Paper
Because your question has numerical data, you can simply use SUMIFS.
SUMIFS provides the sum from a particular range [column D in this case], where any number of other ranges of the same size [the other columns, in this case] each match a particular criteria. For text results, one of the other recommended solutions will be needed.
In addition to being a little cleaner, this has the attribute [could be good or bad depending on your needs] that it will pick up multiple rows of data if multiples exist, and sum them all. If you expect unique rows, that's bad, because it won't warn you there are multiples.
The formula in your case would be as follows [obviously, you should adjust the formulas to reference your ID cells, and pick up the appropriate columns]:
=SUMIFS(D:D,A:A,2015,B:B,"Revenue",C:C,"Name1"))
What this does is:
Sum column D, for each row where: (1) column A is the number 2015; (2) column B is the text "Revenue"; AND (3) column C is the word "Name1".
If assuming your data starts in A1 ("Year") and goes to D15 ("????"), you can use this. You bascically just add your criteria with &, then when doing the Match() regions, connect their respective ranges with & as well.
=Index(D2:D9,Match(A15&B15&C15,A2:A9&B2:B9&C2:C9,0))
and enter with CTRL+SHIFT+ENTER and make the references absolute (i.e. $D$2:$D$9), I just didn't to keep the formula a little easier to read.
Related
I have a chart that shows the salaries for various medical specialties by percentile (each row is a specialty and each column is a percentile).
I want to be able to take a separate chart of physicians and their salaries, and automatically fill in what percentile each of their pay is.
https://i.imgur.com/NCtHHAB.jpg
If the physicians were all in one specialty, then I could just use Index-Match like so:
=INDEX('[Percentiles Chart]'!$B$3:$F$4, 1, MATCH(K3,'[Percentile File]'!$B$4:$F$4,1))
This formula works because it's choosing the column based on just the salaries in that one row, and always returning the top row. If I wanted it to choose between different rows, how could I do that without writing an "If" formula for every single row?
In other words, I want excel to look down column A in the example picture to pick the right specialty, then compare the salaries across the row and return what's in row 2.
Thank you!
As you rightly mentioned, there is no easy way to accomplish what you are looking for since the combination of Index/Offset/Match functions will return the data from the row that is matched and not some other row. Here is a formula that I have tried and it works exactly like you want. It is slightly hacky and uses SUMPRODUCT but gets the job done.
In your spreadsheet, if you enter the below formula, you would see that it gets the correct percentile value.
=OFFSET($B$2,0,SUMPRODUCT(($A$3:$A$6=J3)*($B$3:$F$6<K3)),1,1)
Here is how it works. The first part Sumproduct basically matches the name of specialty in range A3 to A6 and returns true for a match. The second part in sumproduct checks how many values in the range B3 to F6 are less than the given value (for example K3). When these two results are multiplied, it gives the number of values less than given value in the row of matching specialty which is equivalent to the offset of the column in the range. So, the OFFSET function simply navigates to that column and returns the value of the percentile. The below screenshot should help you understand it better.
If my explanation confused you :), you may want to play around with this formula to see how exactly it works.
Note the last column that says 100 in the percentiles table. That is simply to show correct value in case salary is greater than 90 percentile value.
I've been going up and down the internet to solve this. I think I am not searching with the correct parameters but I still hope you can help me.
Sample table:
I have some consolidation forms I need to fill with sums. So, in C19 (which is actually on a new tab) I would like to sum all the values C5-C12 which are mapped to the AB100 account for the consolidation, in production for example. The AB100 account is not unique to production, so I first need to define the column in which the specific row(s) have to be used to sum the values. Automating that in a formula is my key issue here.
I could easily solve this by just selecting column E as range for SUMIF but I want the formula in C19 to be able to recognize which column is to be looked at automatically, e.g. by using a "Lookup Key". I have many of those consolidation forms and I don't want to manually change the formulas on each tab.
It seems to me that all tips I found for nested SUM(IF( or SUM(INDEX( - even as array formulas - have the result value on the intersection of matched row and column. What I have on that intersection is a range of identical account numbers which need to be matched back to their respective $ values in C5-C12.
Any idea how I can do this with a formula?
Use INDEX/MATCH
=SUMIF(INDEX(D5:F12,0,MATCH(C16,D4:F4,0)),B19,C5:C12)
Using an index formula to select the column required in the SUMIFS
Hope this helps!
I've got a bigger table with one column that I want to focus on, containing designation and a number. I want to simply sum the numbers that meet the criteria based on a designation.
For the simplification, I made an exercising sheet (on the pic) where I split second column into two - one string and one numeric. Since my file is quite large with many columns that would need this it would be inconvenient.
In the left column it's easy to solve the problem, it could be even easier with simple SUMIF function, but an array SUM(IF... function is, at least I think, only viable option here.
So I solved the first table with array function, but what confuses me is how to modulate the TRUE statement. Simple replacement of C:C
with
VALUE(MID(F:F;4;4))
which would format my cells to get the numbers from string does not work that way - returns zero in E12 field. F12 is just application of string to number for last cell, F10.
THIS formula does not work, even adapting to different versions of the tool.
I could use VB but if possible anyhow I would like to avoid it since parts will be shared on mobile phones.
Any ideas? Thanks a lot!
Left table was split, right original format
The array formula which you used can be replaced by the SumIf formula like below...
=SUMIF(B:B,"B",C:C)
Also without the helper column, you can use the Sumproduct formula to achieve the desired output.
But don't refer the whole column in the formula like in the above SumIf formula.
Try this..
=SUMPRODUCT((B1:B10="B")*MID(F1:F10,FIND(",",F1:F10)+1,255)*1)
Change the ranges as per your requirement but remember to make them equal in size.
As you can see, I have a database table on the left. And I want to add in IF statement that allows me to lookup the [Code], [Name] and [Amount] of the top 5 of Company A ONLY. Then do a top 5 for Company B and so on. I have managed to lookup the top 5 out of ALL companies but cannot seem to add a criteria to target specific company.
Here are my formulas so far:
Formula in Column K [Company]: = INDEX(Database,MATCH(N3,sales,0),1)
Formula in Column L [Code]: = INDEX(Database,MATCH(N3,sales,0),2)
Formula in Column M [Name]: = INDEX(Database,MATCH(N3,sales,0),2)
Formula in Column N [Amount]: = LARGE(sales,ROW(1:20))
The intended result is to show the top 5 sales person in each company along with their [Code], [Name] and [Amount], feel free to suggest any edits to the worksheet.
Here's an alternative if you know the code is unique. After putting A into K3:K7
First get the highest amounts for Company A starting in N3
=AGGREGATE(14,6,Database[Amount]/(Database[Company]=K3),ROWS(N$1:N1))
Then find the code which matches the amount, but only if it hasn't been used before (this assumes that the code is unique) starting in L3
=INDEX(Database[Code],MATCH(1,INDEX((Database[Company]="A")*(Database[Amount]=N3)*ISNA(MATCH(Database[Code],L$2:L2,0)),0),0))
Then find the matching name with a normal INDEX/MATCH starting in M3
=INDEX(Database[Name],MATCH(L3,Database[Code],0))
Okay, I have achieved this with the use of a helper column which you can hide. Please nnote though that this will only work as long as there are not more than 9 identical totals for any 1 company, I don't think you should have that issue but it may occur, the digits being added by the helper column would need to be tweaked
First Helper Column:
Adds a digit to the end of the total representing the number of times that amount already exists above for that company. This formula is =CONCATENATE([#Amount],COUNTIFS($A$1:A1,A2,$D$1:D1,D2))*1
This is multiplied by 1 to keep the number format for LARGEto work with.
Second Helper Column:
This is an array formula and will need to be input by using Ctrl+Shift+Enter while still in the formula bar.
The formula for this one is:
=LARGE(IF(Company="A",Helper),ROW(1:1))
What this formula does as an array formula is produce a list of results based on the IF statement that LARGE can use. Rather than the entire column being ranked largest to smallest, we can now single out the rows that have company "A" like so:
=LARGE({20000;20001;20002;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;15000;14000;30000;FALSE;FALSE;FALSE;FALSE},ROW(1:1))
LARGE will only work with numeric values so the FALSES produced where column A does not match "A" will be ignored. Notice why I have used the helper column here to eliminate unique values but not affect the top 5.
ROW(1:1) has been used as this will automatically update when the formula is dragged down to produce the next highest result in this array.
The main formula for top 5 array
Again this is an Array formula so will need to be input by using Ctrl+Shift+Enter while still in the formula bar.
=INDEX(Database,SMALL(IF(Company="A",IF(Helper=$O3,ROW(Company))),1)-1,COLUMN(A:A))
With array formulas for some unknown reason IF(AND()) just does not work for me so I have nested two IF's instead.
Notice how I am again checking whether the first column matches "A" and then whether the last column matches the result of the second formula. What will happen is where both of these conditions match in the array (as in both produce TRUE for the same row) I wanted the row number to be returned.
IF({TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE},IF({FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;FALSE},{2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20}))
It looks like a mess I know, but the position where both TRUEs align gives us the row 16 as a result.
{FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;16;FALSE;FALSE;FALSE;FALSE}
As I know that there can only be one match possible for this, I use SMALL to grab the first smallest number to use in the INDEX formula for row and deduct 1 as we are not considering the headers in the INDEX formula so we actually want the 15th result.
Again, COLUMN(A:A) has been used for the column number to return as this will automatically update when the formula is dragged across.
If you are struggling with my explanation and want me to provide more clarity, feel free to reach out and I will try my best to explain the logic in more detail
I have created an excel spreadsheet to keep track of the >400 different types of beer that I have tried along with their home brewery, alcohol content, & rating. I have used array formulas to calculate how many different breweries and how many beers from each brewery as well as how many different styles and how many of each style I have tried. The problem I am running into is sorting the data. I have a list of all the various breweries (excluding duplicates) in column K. In column L I have the # of different beers I have tried from each brewery. I would like to sort columns K & L from most largest to smallest using the values in column L. Same thing applies for columns M & N except it's the styles not the breweries I'm tracking. I can't figure out how to do it since I'm using two array formulas, one in each column, and basically the results are conditioned on the results of the other. Any help on this matter would be greatly appreciated. Below is a link so you can download the spreadsheet to better understand what I'm doing.
https://www.dropbox.com/s/cysa2rvcgcbs13c/TGS.xlsx?dl=0
Also the array formulas I'm using to make the unique lists in columns K and M are my first try at array formulas. Therefore, if someone could tell me if they are efficient or not and if there's a better way to do what I'm trying to do which is look through the data in column B, discard the duplicates, and extract the unique breweries into column K. Same thing applies the styles in columns C & M.
Thanks in advance!
While it is marginally possible to perform all counting and ranking within a single formula, the use of Helper columns makes much more sense and reduces calculation load substantially. For all intents and purposes, your existing unique lists and COUNTIFS are what the helper columns would contain and then you can return the values to another column based on the ranking of the COUNTIF returns.
I modified your array formula from K2 and put it into P2 as,
=IF(LEN(P1), IFERROR(INDEX($B$2:$B$501, MATCH(0, IF(LEN($B$2:$B$501), COUNTIF(P$1:P1, $B$2:$B$501&""), 1), 0)), ""), "")
The standard formula in Q2 was similar to the one previously in L2 as,
=IF(LEN(P2),COUNTIF($B$2:$B$501,P2), "")
The formula in L2 could now return a ranked result from column Q with this standard formula,
=IFERROR(LARGE($Q$2:$Q$501, ROW(1:1)), "")
With the ranked return in L2, K2 could return a matching brewery from column P with this array formula,
=IF(LEN(L2),INDEX($P$2:$P$501,SMALL(IF($Q$2:$Q$501=L2,ROW($1:$500)), COUNTIF(L$2:L2, L2))),"")
Columns S, T, M and N were similarly modified. Then everything was filled down to row 501.
I've made the modified workbook available on my SkyDrive here for you to reference and download. Let me know if you want it removed.
TGS (Jeeped).xlsx
More information on this method from Multiple Ranked Returns from INDEX(…) with Duplicate Values