Modify Countif rank formula so that matching results only count once - excel

So I have this spreadsheet
I am trying to workout the most picked item out of each bin based on the style and colour, I have created a sumif formula that counts and adds all of the items that is the same colour. I am now trying to create a ranking for each item based upon the Style Color Pick QTY and the month.
=(COUNTIFS(A:A,[#[bin-name]],I:I,[#Month],K:K,">"&[#[Style Color Pick QTY]])+1)
The problem is that it ranks every individual line, so instead of PS-1 Scarlet having a rank of 7 I would like it to have a rank of 2.
I have tried adding extra conditions to this such as an extra sumif that checks the previous result, or putting them in IF statements to compare to other results but all of my attempts result all Ranks being 1 or not changing.
So I am looking to modify this formula or being able to write a =unique() formula in another sheet and run the Rank Countif formula against that, I am able to write this but not sure how how to embed the # to make the formula dynamic(i.e. So i'm not dragging the formula down 1000 lines).
Any help would be appreciated.

I found an unelegant solution to your problem. This approach might be able to be refactored into a more elegant solution though.
Column Rank is the column you already have.
Column Uniques is a helper column that has the formula =IFERROR(INDEX([Rank]; MATCH(0; INDEX(COUNTIF($B$1:B1;[Rank]); 0; 0); 0)); "") in its first cell B2.
Getting the Proper_Rank is now as easy as =RANK([#Rank];[Uniques];1).
The two helper columns Rank and Uniques can of course be hidden or placed wherever you want. As I said, it's probably possible to combine these helper columns into one calculation, but I don't know how.

Related

Getting Top Values from One Sheet and inputting onto a different sheet

So I'm going to eventually have 3 sheets. Sheet 1 is where I have data (numbers for a category and a name associated with it. Sheet 2 is where I pull the top 5 users for each category. Sheet 3 is where I have a leaderboard for points gained.
Right now I'm trying to work with Sheet 2 (grab the top 5 performers from each category. I'm fairly new to Excel, but after some research it seemed that XLOOKUP would be the way to go. (i'll attach screenshots below.
I'm using this formula:
=XLOOKUP(LARGE('Cases Test for Categories'!$C$18:$C$55,1),'Cases Test for Categories'!$C$18:$C$55,'Cases Test for Categories'!$A$18:$A$55)
however when using it I get all 0's.
Here's a screenshot of values I'm trying to grab from "Warranty Service Request"
and here is a screenshot when applying my formula
The solution I would want is to grab the 5 largest numbers from sheet 1 with the person name as well.
I don't think that XLOOKUP can get you anywhere near what you want but the formula below will get you one step closer.
=INDEX(List,MATCH(LARGE(INDEX(List, ,2),1),INDEX(List,,2),0),1)
In fact, it's the explanation of that formula which will be of help. Here we go.
List is a named range, perhaps equal to your 'Cases Test for Categories'!$C$18:$C$55. The reason for using a name is obvious. It's shorter. In my test List = A2:B6, in case you want to reconstruct it. Column 1 has names, column 2 numbers.
The term INDEX(List,,2) specifies the second column of List. You can replace the '2' with a formula to specify different columns of the named range.
In fact, INDEX(List,,1) does specify the first column and INDEX(List,4,1) specifies the 4th cell in that column, and that is exactly what you see in my formula. All of MATCH(LARGE(INDEX(List, ,2),1),INDEX(List,,2),0) just serves to find the row number in List, in this example the number 4.
Of course, LARGE(INDEX(List, ,2),1) returns the largest number in column2 of List. The '1' can be replaced by a formula, for example ROW()-1 which would return 1 if placed in row 2 and count up from there as it's copied down. Try =ROW()-1 in any cell in row 2 and copy the formula down.
MATCH([LARGEST],INDEX(List,,2),0) returns the row number where the largest was found, and that is the number we need to return the name from the first column of List.
This will work perfectly for one column and can easily be modified to work for different columns. Your question doesn't specify how you would like to arrange the 5 results from each category but the formula can be modified a little to accommodate whatever you want. What it can not do is to deal with ties. MATCH(LARGE can only find the first of several identical results.
To break ties in this sort of operation is complicated and must be done ether by helper columns in the data table or using VBA. It's definitely the topic of another question. For now I hope that it's a problem you will not have to anticipate.

Array formula to switch selection

I am trying to determine the top 3 depending on the selected criteria, amount or count. User can choose between the two. I have the formula to determine top 3 but I don't know how to modify it to take in account of user's selection. User's selection is in J2.
In this case, count is selected but as you can see, my formula spits out amount.
I think I need an array formula nesting choose or offset or something. The formula I have in the selected cell is
=INDEX($A$3:$A$35,MATCH(1,INDEX(($E$3:$E$35=LARGE($E$3:$E$35,ROWS(I$7:I7)))*(COUNTIF(I$7:I7,$A$3:$A$35)=0),),0))
which calculates top 3. How can I get that to change depending on user selection?
Edit: I realize I can have two sets of data for each criteria and do an offset to select between the two but figured one of you wizards can probably do it all in one. (This data is used to drive a graph.)
Edit2: sorry if it was too abstract. There are two columns. E and F. E is a list of amounts. F is a list of counts. I want to find the top 3 of both. But obviously only one at a time. Depending on what the user chooses.
As you can see, even though the selection is currently count (J7), the results show the top 3 by amounts.
By using the number selected in J2, I should be able to nest an offset function to grab the column desired yes? 1 for column E, 2 for column F. That's how I understand the function to work. However, my attempts to nest has failed because I believe I need an array formula which is beyond my skillz.
Edit3: see pic. It shows the top 3 by each criteria. How do I combine them?
You could combine it into one (non-array) formula. Here is a simple example which perhaps you can adapt to your situation.
This is the formula in J7. Change the 2 in J2 to 1 and it will return the largest value in E rather than F.
=INDEX(OFFSET($E$3:$E$35,,J2-1,,),MATCH(1,INDEX((OFFSET($E$3:$E$35,,J2-1,,)=LARGE(OFFSET($E$3:$E$35,,J2-1,,),ROWS(I$7:I7)))*COUNTIF(I$7:I7,$A$3:$A$35)=0),),0))

Returning sum of column for filtered data, without filter

I'm trying to calculate the sum of a column (TSQFT in the screenshot) that is part of a data set, which would be filtered based on multiple criteria using cell references (see screenshot). I don't want to use excel's regular filter as it's a hassle to change the settings and I'd like it to be done in a more automated way.
I've tried {SUMIF} and {SUMIFS} but those do not work as a filter - i.e. for a row to be {TRUE}, the numbers have to be in the same order as that specified in the criteria list {5-7-2} (see screenshot).
Would much appreciate any help.
You can try something like this:
Make 3 column of =IF(OR(C3=$C$10;C3=$D$10;C3=$E$10);1;0) formulas, one more column for a sum of this 3 column and a sumif based of the sum values
if the sum is 3 then the value is good.
This maybe the worst solution for this but as long as it can help, it can be developed into something better.

VBA code required to loop through different sized rows of data and return MAX value

I am currently automating a dashboard creation and I've hit a bit of a roadblock. I need some code that will go through about 7000 rows of data and return the highest value in a certain column for each specific item. The data is copied from a pivot table and so is broken down into row sections, I have attached a mock of what it looks like.
I need the highest value in Column G for each portfolio, and will need to use the portfolio code (e.g. XY12345 - They are always 7 characters) to map that value to the dashboard.
My issue is, each portfolio has a different number of rows for the values, and some have blank cells between them, and therefore I am stumped. I was hoping to use Column J to count the number of rows for each portfolio (as there are no breaks for the portfolios in this column) and then use a loop to loop through each portfolios rows of values, based off the Column J count, and then return the highest row value for each portfolio. Problem is I'm new to VBA and have been teaching myself as I go, and I've yet to use a loop.
Many thanks,
Harry
If I understand correctly, you're looking for the largest value in Column G.
I'm not sure why you think you would need VBA for this.
Get the maximum value of a column
You mentioned that you're concerned about each column not having the same number of cells but that's irrelevant. as SUM ignores blank cells, so just "go long", or - find the maximum of the entire column.
To return the largest number in Column G you could use worksheet formula :
=MAX(G:G)
The only catch is that you can't place that formula anywhere column G or else it would create a circular cell reference (trying to infinitely add a number to itself). let's pit that formula in cell F1 for now (but anywhere besides column G would do fine).
Find the location of a value
Now that you know the largest value, you can determine where it is using a lookup function such as MATCH or VLOOKUP. Like with so many things in Excel, there are several ways to accomplish the same thing. I'll go with MATCH.
Replace the formula from above (in F1) with:
=MATCH(MAX(G:G),G:G,0)
This will return the row number of the first exact match of the maximum value of Column G.
As for the third part of question: returning the code like X12345 where the value exists, will be a little tricky since your data is not organized in a logical tabular style (tabular meaning, "like a table").
Your data is organized for humans to look at, not for machines to easily read and manipulate it. (See: Office Support: Guidelines for organizing and formatting data on a worksheet)
Basically, when organizing data in rows, all relevant information should be on the same row (not a subjective number of rows behind). Also, you have the number combined with other information.
My suggestion for a quick fix:
Right-click the heading of Column C and choose Insert to insert a blank column.
In C2 enter formula: =IF(B2="",C1,LEFT(B2,7))
Copy cell C2
Select cells in column C all the way to the "end" of your data, where ever that is (not the end of the worksheet). For example maybe you would select cells B2:B1000)
Paste the copied cell into all those cells.
Now, you can again modify the formula in F1:
=INDEX(C:C,MATCH(MAX(G:G),G:G,0))
This will return the value from Column C in the same row that the maximum value of Column G is located.
This is known as an INDEX/MATCH formula.
Hopefully this works for you in the interim until you can organize your data more logically. There's lots of related information and tutorials online.

Pulling value from cells in Excel based on top 5 value in a different column

Let's say column A has ten names in it, and column B ten values. I want the names of the people with the five highest column B values, in order, to populate on a different sheet. How would I do this? What if I wanted the lowest values?
you can also use vlookup to achieve the same but since your lookup value comes before the column you are looking up against then you need to use choose function to resolve this:
always using the same example table
put this formula in C2 to pull the top 5:
=VLOOKUP(LARGE($B$2:$B$99,ROW(1:1)),CHOOSE({2\1},$A$2:$A$99,$B$2:$B$99),2,0)
and put this in D2 to pull the low 5:
=VLOOKUP(SMALL($B$2:$B$99,ROW(1:1)),CHOOSE({2\1},$A$2:$A$99,$B$2:$B$99),2,0)
hope this works as well.
you can use the index matchfunction to achieve this:
Given the above example table:
Formula to pull top 5, put this in C2:
=INDEX($A$2:$A$99,MATCH(1,INDEX(($B$2:$B$99=LARGE($B$2:$B$99,ROWS(C$1:C1)))*(COUNTIF(C$1:C1,$A$2:$A$99)=0),),0))
Formula to pull low 5, put this in D2:
=INDEX($A$2:$A$99,MATCH(1,INDEX(($B$2:$B$99=SMALL($B$2:$B$99,ROWS(D$1:D1)))*(COUNTIF(D$1:D1,$A$2:$A$99)=0),),0))
For both, drag and fill down for 5 rows (because you want top/low 5). you can drag/fill down as many as you want.
you can adapt it to fit the lenght of your column by changing the $A$99 and $B$99 to any number of rows you have.
tell me if it works for you.

Resources