Excel - getting a value based on the max value off another row in a Table - excel

I'm looking for a solution for a problem I'm facing in Excel. This is my table simplified:
Every sale has an unique ID, but more people can have contributed to a sale. the column "name" and "share of sales(%)" show how many people have contributed and what their percentage was.
Sale_ID
Name
Share of sales(%)
1
Person A
100
2
Person B
100
3
Person A
30
3
Person C
70
Now I want to add a column to my table that shows the name of the person that has the highest share of sales percentage per Sales_ID. Like this:
Sale_ID
Name
Share of sales(%)
Highest sales
1
Person A
100
Person A
2
Person B
100
Person B
3
Person A
30
Person C
3
Person C
70
Person C
So when multiple people have contributed the new column shows only the one with the highest value.
I hope someone can help me, thanks in advance!

You can try this on cell D2:
=LET(maxSales, MAXIFS(C2:C5,A2:A5,A2:A5),
INDEX(B2:B5, XMATCH(A2:A5&maxSales,A2:A5&C2:C5)))
or just removing the LET since maxSales is used only one time:
=INDEX(B2:B5, XMATCH(A2:A5&MAXIFS(C2:C5,A2:A5,A2:A5),A2:A5&C2:C5))
On cell E2 I provided another solution via MAP/XLOOKUP:
=LET(maxSales, MAXIFS(C2:C5,A2:A5,A2:A5),
MAP(A2:A5, maxSales, LAMBDA(a,b, XLOOKUP(a&b, A2:A5&C2:C5, B2:B5))))
similarly without LET:
=MAP(A2:A5, MAXIFS(C2:C5,A2:A5,A2:A5),
LAMBDA(a,b, XLOOKUP(a&b, A2:A5&C2:C5, B2:B5)))
and here is the output:
Explanation
The trick here is to identify the max share of sales per each group and this can be done via MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...). The size and shape of the max_range and criteria_rangeN arguments must be the same.
MAXIFS(C2:C5,A2:A5,A2:A5)
it produces the following output:
maxSales
100
100
70
70
MAXIFS will provide an output of the same size as criteria1, so it returns for each row the corresponding maximum sales for each Sale_ID column value.
It is the array version equivalent to the following formula expanding it down:
MAXIFS($C$2:$C$5,$A$2:$A$5,A2)
INDEX/XMATCH Solution
Having the array with the maximum Shares of sales, we just need to identify the row position via XMATCH to return the corresponding B2:B5 cell via INDEX. We use concatenation (&) to consider more than one criteria to find as part of the XMATCH input arguments.
MAP/XLOOKUP Solution
We use MAP to find for each pair of values (a,b) per row, of the first two MAP input arguments where is the maximum value found for that group and returns the corresponding Name column value. In order to make a lookup based on an additional criteria we use concatenation (&) in XLOOKUP first two input arguments.

Related

How to return count of number in sequence after validating three values from 3 different columns even though there will be matched data found?

I have a range of cells in excel. How to increment numbers when meeting data validation from three different columns?
I tried using formula COUNTIF($A$2:A2,A2) which creates a number sequence. But I have other data to validate from another column for it to return the correct number sequence.
First validation: count the emp no in column range A1:A5 which return a result under Hierarchy column.
Second validation: check the % value under column L as per below level of hierarchy in which the problem comes from.
1 - 0.25
2 - 0.25
3 - 0.5
4 - 0.5
5 - 1
Third validation: check the type of Relation (see Relation column) that needs to check when returning number of sequence too. Below is the Relation Level table.
I don't know on how to join these three conditions for the result to be as below.
My really problem here is on how will i get a sequence number if a person does have 3 children and should be tagged as 2,3,4 (next to spouse which is 1) then the next relation which is parent will be tagged then as next number sequence from the last count of child wherein will be 5 given that as per relation table, Parent level is 3 but it will be adjusted as per count of relations a person has. And for this specific instance, if Parent count will be 5, it still should have 0.5 EE % (see relation table level vs % hierarchy level) even though the count of number is 5. I hope this will make sense. But let me know if you have any questions.
Hope someone could help me on this coz I am not that expert when it comes to excel formula. Thank you!

Count Unique Dates Associated with Location

I am trying to count the total of Unique Dates based on the location.
Context: I trying to create a formula for counting the number of unique dates based on location. My Spreadsheet looks like this
A B C
1 **Participant Location Date**
2 Participant-A High School X 11/7
3 Participant-B High School X 11/7
4 Participant-C High School X 11/8
5 Participant-E High School Y 11/7
6 Participant-F High School Z 11/7
7 Participant-G High School Z 11/8
So for example: high School X had 2 different dates. What would the formula be to count the unique dates based on the location?
This is also being completed on google sheets.
Thank you!
Another way (with no helper columns) would be to use query() and unique().
=query(unique(B:C), "Select Col1, count(Col2) where Col1 <>'' group by Col1 label count(Col2)'# of unique dates'", 1)
Illustration:
With a simple helper column :
=1/COUNTIFS($A$2:$A$7,A7,$B$2:$B$7,B7)
And to get your results :
=SUMIF($A$2:$A$7,E2,$C$2:$C$7)
This is not one-formula solution but I think it works. First, create a third column concatenating the columns that you want to compare. In this case, at cell D2 write:
=CONCATENATE(B2,C2)
This is for the first row of your example. Then, replicate that to the following rows.
Finally, create a formula that counts unique values:
=SUM(IF(FREQUENCY(IF(LEN(D2:D7)>0,MATCH(D2:D7,D2:D7,0),""), IF(LEN(D2:D7)>0,MATCH(D2:D7,D2:D7,0),""))>0,1))
Assuming your new column of concatenated values is at D2:D7.

Search a Column for Specified Text, Then Return the Sum of the adjacent column which contains values to sum

I am creating a World Cup spreadsheet.
Example:
Team | Pts |
Brazil | XXX |
Switz. | XXX |
C. Rica| XXX |
Serbia | XXX |
I have another table which displays the Country, Score & whether it was a W (win), L (loss) or T (tie). A WIN will add 3 points, a TIE will add 1 point & a LOSS will add 0 points. Where I put the XXX, I want a formula that will search the table column for the Country Name and ADD up the W's, L's & T's and display the sum of every game there team played with the point system I mentioned.
Any help would be greatly appreciated! Thanks.
Try,
=SUM(COUNTIFS(D:D, A2, E:E, {"T","W","W","W"}))
You can use COUNTIFS. I set up a mock table to demonstrate:
The first COUNTIFS will count a given teams wins, and then multiple by a factor of 3.
The second COUNTIFS will count a given teams ties (no need to multiply here).
Since a Loss equates to 0 points, there is no need to sum or count anything.
Adjust ranges to fit your setup and then auto-fill the equation down your table to calculate for each team.
You can use a formula in H2, as below, and drag down as many rows as required
=(3*SUMPRODUCT(--($A$2:$A$13=$G2),--($C$2:$C$13="W"))+SUMPRODUCT(--($A$2:$A$13=$G2),--($C$2:$C$13="T")))
Data:
You only care about Wins or Ties. So count the wins per country and * 3 and add to that the count of ties, which you don't need to multiply as is 1.
Sumproduct is used to handle the arrays nicely.

Google Sheets Arithmetic Search

I have two Google sheets tabs:
I.)
--A-- --B--
--1-- type lessThan10Apart
--2-- Car 1
--3-- Plane 0
II.)
--A-- --B-- --C--
--1-- type sourceA sourceB
--2-- Car 1 100
--3-- Plane 10 100
--4-- Car 2 4
My question is how to create the lessThan10Apart formula above. lessThan10Apart should match up the type from sheet I to sheet II and only count the rows that: Are less than 10 units between A and B. But you can also imagine wanting to do any kind of arithmetic between columns B and C and running a COUNT.
My first attempt is something along the lines of:
=COUNTIFS('sheetII'!A:A),$A2, //Match column A
ABS('sheetII'!C:C-'sheetII'!B:B)<10 //Doesn't work!
)
The problem is that you can't seem to be able to do range calculations like this in COUNTIFS.
For the count (per F4 in supplied image),
=SUMPRODUCT(--(ABS(B2:B4-C2:C4)<10))
For the validSum (sum of absolute difference between B & C; per G4 in supplied image),
=SUMPRODUCT(--(ABS(B2:B4-C2:C4)<10), ABS(B2:B4-C2:C4))
Do not use full column references. Minimize your referenced ranges.
Discard the Car text in E4 in the above image.

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