Keeping rows based on source rankings in excel? - excel

I have a table that looks like this -
Source Rank
Value
1
A
2
A
3
A
2
B
3
B
1
C
2
C
3
C
I want to make only keep the rows for each value with best rank. So the table will look like this -
Source Rank
Value
1
A
2
B
1
C

It's almost impossible to find a better argument for the invention of the "Subtotals" feature, as you can see:
Oh, in case you don't get the same results immediately: don't forget to click the 2 button in the left margin :-)

Create a Pivot Table from the source data, and set:
Row Labels: Value
Values: Source Rank - and use the pulldown to set to Min
Admittedly this will have the columns the other way round from what you show as ideal result.

Related

How to create a count table of two variables in excel pivot

I am struggling with creating a count table of two variables at the same time. Ultimately, I would like to create a bar graph of the table.
Assuming I have two items for a sample of firms and I just want a summary table of the answer count.
Firm Item1 Item2
1 1 1
2 2 1
3 1 2
4 1 2
Based on this answer, I can easily create the summary table for Item 1 telling me that "1" appears three times for item 1 and two times in Item 2. But I cant easily create a Pivot table showing this jointly.
I'm not sure I understood correct, but is it COUNTIF() you need?
In D1 type:
=COUNTIF(B:B, "1")
that should give you result 3

Multiple Calculated Columns with Filters within Single Pivot Table

I am working to create a Pivot Table in Excel that has multiple calculated fields that take into account whether a condition is true, but cannot figure out how to create this within a single Pivot Table.
Behind the scenes, I have a set of data with a column that can have these values: A,B,C,D,F,L, or R.
I have another column that is a dollar value, and another for Quantity.
I am trying to calculate the price per unit when the Category is A,B, or C, but also calculate the price per unit when the Category is D.
I can create multiple Pivot Tables and tie them to the same slicer, but the issue is this: I need to display the spending in each of the two categories for each location, and when I create two separate Pivot Tables for this, locations that do not have spending in one of the categories are excluded (in this below case, location 2 has no spending in Category D, so it does not show up in the second Pivot Table).
Here is a portion of my data set. The whole data set is over 100,000 rows and will change over time, so I do need a solution for the long-term.
Location Category Volume Quantity
1 A $120.32 6000
3 A $30.08 1300
3 A $60.16 2600
1 B $39.91 1000
2 B $318.50 13000
2 C $196.00 8000
1 D $220.50 8100
3 D $171.50 6300
3 D $35.90 1000
3 D $53.85 1500
2 F $416.50 0
1 L $24.50 0
2 L $30.08 0
1 R $55.13 0
2 R $55.13 0
3 R $110.26 0
Thanks in advance for your help and let me know if I need to clarify anything!
Alright, a little more digging yielded the answer.
A slicer should be included that has all locations selected, then it should be tied to all Pivot Tables in use.
For all Pivot Tables, go to Field Settings, then click on the Layout and Print Tab. Check the box 'Show items with no data'.
Then go to Pivot Table Options and select the values you would like to display for blanks and errors.
I found the solution here.

Excel formula to apply penalty column to ranking

I have thought long and hard about this, but I can't find a solution to what I believe is quite a simple problem.
I have a table of results, where sometimes someone will be given a penalty of a varying amount. This is entered into the penalty column (Col C).
I need a formula which checks if there is an entry into the penalty column and applies it, not only to that row, but to the number of subsequent rows which are affected, depending on the severity of the penalty.
I have tried to see if this is possible by referencing the penalty against the 'ROW()' function but have not been able to achieve the desired effect.
Col D shows the desired output of the formula.
Col E is included for reference only, to show the desired effect on each row.
Col A Col B Col C Col D Col E
Pos Name Penalty New Pos Change
1 Jack 1 0
2 Matt 2 0
3 Daniel 2 5 +2
4 Gordon 3 -1
5 Phillip 4 -1
6 Günther 6 0
7 Johann 3 10 +3
8 Alain 7 -1
9 John 8 -1
10 Gianmaria 9 -1
The big issue is, if someone is handed a big penalty, for example '10' then it affects the following ten rows. I can't work out how to include this variable logic...
I would be interested to hear the approach of others...
You need to use the RANK() function:
Excel RANK Function Examples
In a new column, add the penalty value to the original position, plus a small coeffieient depending on the original position (0.01 per increment perhaps) to move the penalised player below the original person at that position, then in the next column you can RANK() the new column of values (F in my case).
New value is therefore =A2+(IF(C2>0,C2+(0.01*A2)))
Rank is then =RANK(F2,F2:F11,1)
You can combine all the functions into one, but it's clearer to do it in separate columns at first.

How to get a column name based on function

Suppose I have a dataset:
A B C Final
1 2 3 C
4 5 6 C
I want final to return the column name of the max value. In the example above, 3 and 6 are the highest values, so columns C will be returned in the 'Final' column.Is there an efficient way/formula you can use to get the column names without using VBA? the real dataset containts 60 columns.
I would try something like this to get the column letter.
=SUBSTITUTE(ADDRESS(1,MATCH(MAX(A3:C3),A3:C3,0),4),1,"")
If you want the header, I think there's an easier way, but the extension from this would be
=INDIRECT(SUBSTITUTE(ADDRESS(1,MATCH(MAX(A3:C3),A3:C3,0),4),1,"")&1)
For the header, the better way
=INDEX(A1:C1,1,MATCH(MAX(A3:C3),A3:C3,0))
HLOOKUP is a way without VBA, but sadly HLOOKUP does only search in the first row of the array, so you should add the "title column" at the bottom
A B C Final
1 2 3 <formula1>
4 5 6 <formula2>
A B C
If the dataset starts at first corner, Formula1 would be :
=HLOOKUP(MAX(A2:C2);A2:C4;2;FALSE)
Formula2 will be
=HLOOKUP(MAX(A3:C3);A3:C4;1;FALSE)
etc...
=HLOOKUP(MAX($A3:$C3);$A3:$C$4;<manual change here backward>;FALSE)
You can use the vector form of the LOOKUP function.
If your first row, with A B C, are the labels, then:
=LOOKUP(2, 1/(MAX(A2:C2)=A2:C2),$A$1:$C$1)

Find the top n values in a range while keeping the sum of values in another range under x value

I'd like to accomplish the following task. There are three columns of data. Column A represents price, where the sum needs to be kept under $100,000. Column B represents a value. Column C represents a name tied to columns A & B.
Out of >100 rows of data, I need to find the highest 8 values in column B while keeping the sum of the prices in column A under $100,000. And then return the 8 names from column C.
Can this be accomplished?
EDIT:
I attempted the Solver solution w/ no luck. 200 rows looks to be the max w/ Solver, and that is what I'm using now. Here are the steps I've taken:
Create a column called rank RANK(B2,$B$2:$B$200) (used column D -- what is the purpose of this?)
Create a column called flag just put in zeroes (used column E)
Create 3 total cells total_price (=SUM(A2:A200)), total_value (=SUM(B2:B200)) and total_flag (=(E2:E200))
Use solver to minimize total_value (shouldn't this be maximize??)
Add constraints -Total_price<=100000 -Total_flag=8 -Flag cells are binary
Using Simplex LP, it simply changes the flags for the first 8 values. However, the total price for the first 8 values is >$100,000 ($140k). I've tried changing some options in the Solver Parameters as well as using different solving methods to no avail. I'd like to post an image of the parameter settings, but don't have enough "reputation".
EDIT #2:
The first 5 rows looks like this, price goes down to ~$6k at the bottom of the table.
Price Value Name Rank Flag
$22,538 42.81905675 Blow, Joe 1 0
$22,427 37.36240932 Doe, Jane 2 0
$17,158 34.12127693 Hall, Cliff 3 0
$16,625 33.97654031 Povich, John 4 0
$15,631 33.58212402 Cow, Holy 5 0
I'll give you the solver solution as a starting point. It involves the creation of some extra columns and total cells. Note solver is limited in the amount of cells it can handle but will work with 100 anyway.
Create a column called rank RANK(B2,$B$2:$B$100)
Create a column called flag just put in zeroes
Create 3 total cells total_price, total_value and total_flag
Use solver to minimize total_value
Add constraints
-Total_price<=100000
-Total_flag=8
-Flag cells are binary
This will flag the rows you want and you can grab the names however you want.

Resources