Excel: Calculations with two variables, that both share the same ID - excel

I have been working on a little project in which I analyze some data from a game that I play. My dataset looks like this:
As you can see, it consists of:
Match ID
Map the match was played on
Team name
First pick, second pick and third pick (characters/players)
Points the teams won from this match
What side they played on (A or B)
Who won
Whether they're in the top 64 teams
Currently I am trying to analyze how certain picks perform against other picks. For example, I would like to see how the Xelor first pick (cell D2) performs against all other first picks. To do this, I would need to count the amount of times the Xelor first pick played against all other first pick, and how many times the Xelor pick won. I don't have any problems doing that, but the catch is that I need to make sure I only compare the Xelor first picks with other first picks from the same match (same match ID). For example, I would compare the Xelor first pick (D2) vs the Steamer first pick (D3), as they share the same match ID.
I came up with a messy solution earlier with simple formulas, but it made for a table that had no data every other row, which resulted in some problems analyzing the data. I am now struggling with the Index and Match functions to make a pretty table for my needs, but I am having a hard time.
If anyone could give me a hand on how to do this, or has any clever ideas on how to analyze all picks vs other picks, let me know!

So, it turns out that both the Unique function and the Xlookup functions made this an easy problem to solve.
First, I made a new column showing just the unique match ID values:
=UNIQUE(A:A)
Then, next to that column I looked up the first pick of the A side team using Xlookup:
=XLOOKUP(M2;A:A;C:C;;0;1)
I then did the same in another column for the team on the other side using an inverse search direction:
=XLOOKUP(M2;A:A;C:C;;0;-1)
Lastly, to see which of the two first picks won, I used this formula in a fourth column:
=IF(XLOOKUP(M2;A:A;H:H;;0;1)="Win";N2;O2)
This resulted in the following table (M:P):
Thanks for the help, David!

You could try something like this in M2 cell:
=IF(L2="","",COUNTIFS(TB_GAMES[W/L/D],"Win",
TB_GAMES[Pick 1],L2,TB_GAMES[Match],$K$2))
Then you can expand the formula down.
In L column you have the unique values from users given the Match (K2) and the Pick 1 column values.
=UNIQUE(FILTER(TB_GAMES[Pick 1], TB_GAMES[Match]=K2))
Update
In case you want to calculate the scores for all the Pick 1 players at once. You can try the following:
=LET(winSet, FILTER(TB_GAMES[Pick 1], TB_GAMES[W/L/D]="Win"),
matches,XMATCH(winSet, UNIQUE(winSet)),
freq,FREQUENCY(matches, UNIQUE(matches)), SORT(HSTACK(UNIQUE(winSet),
FILTER(freq, freq<>0)),2,-1)
)
Note: Because we are using a FILTER function we cannot use as range input argument for COUNTIF or COUNTFS, so we try to use XMATCH/FREQUENCY as a way to achieve the same result. For more information about this see my answer to the question: How to count the number of trades made on a Excel spreadsheet using a custom conditional formula?, we use here the same idea and the explanation would be the same.
The HSTACK function is used just to combine the result having the winners and the number of wins for each player. Finally the result is sorted by score.
This would be the result on O2 cell:

Related

Match and Conditional Formatting from Matrix Table

I am looking for some decent help with my matrix table, and is there a good or best approach to properly match dependent instances in certain matrix using drop downs.
This picture represents my matrix table (Picture 1):
As you can see there are a lot of instances, but horizontally and vertically they got the same number of "headers". Those "1`s" are representing not compatibility in my case but lets call it simply "match". That is on one sheet that is gonna be populated with some new values from time to time.
On another sheet which is actually sheet for showing the data and their compatibility possibilities is equipped with drop downs. There you got "Groups (Group1, Group2...)" in a sense of main parts and "dependent groups (AA1, BB2..)" as small components that are part of main parts. To avoid misunderstanding here you have explanations, I used for the sake of this example fictional values:
Groups aka. Main Parts
Dependent groups aka. components
As you can see beneath, is my fictional table but exactly the same concept as I should use in my real case.
I PUT AN EXPLANATION IN THE PICTURE 2 SO YOU CAN FOLLOW ALONG AND SEE EXACTLY WHERE/WHAT I DID!
What I used firstly there are =match functions, one for vertical position (A3) and one for horizontal (B4). This boolean row is done using =or(index) but reffering to the match positions as you can see. And from there I should use true/false for coloring my group boxes in a case compatibility is possible - thats all the science.
So, my question is if there is another approach to this problem? As you can see I have 3 different rows of functions at one place, or imagine if I will have more "groups" that can rise in many more rows and calculations.
Picture 2
EDITED:
This is screenshot of the original sheet, I just hid some rows that were with Infos that is reason the number is not consistent. As you can see it is almost the same as dummy example I provided above. Underneath every "box" you got three rows of calculations as I mentioned before. The two times number "2" that you see here is the position of some value that I found using =match function, one is for horizontal and another for vertical lookup. In this case it is model type, 070FX is position 2, 100FX is 3 and 200FX is 4th position in the matrix table, and so on for all the other groups. And those groups (Model, Endpoint, Gas sensor...) are defined separately on another sheet where I had to make unique list and dependent list so I can reference those to my drop down list.
EDIT Nr 4! So this formula I used for true/false:
=SUMPRODUCT(('0359-matrix'!$A$2:$A$101=F10)*(('0359-matrix'!$B$1:$CW$1=$B$10)+('0359-matrix'!$B$1:$CW$1=$C$10)+('0359-matrix'!$B$1:$CW$1=$D$10)+('0359-matrix'!$B$1:$CW$1=$E$10)+('0359-matrix'!$B$1:$CW$1=$F$10)+('0359-matrix'!$B$1:$CW$1=$G$10)+('0359-matrix'!$B$1:$CW$1=$H$10)+('0359-matrix'!$B$1:$CW$1=$I$10)+('0359-matrix'!$B$1:$CW$1=$J$10)+('0359-matrix'!$B$1:$CW$1=$K$10)+('0359-matrix'!$B$1:$CW$1=$L$10)+('0359-matrix'!$B$1:$CW$1=$M$10)+('0359-matrix'!$B$1:$CW$1=$N$10)+('0359-matrix'!$B$1:$CW$1=$O$10)+('0359-matrix'!$B$1:$CW$1=$P$10)+('0359-matrix'!$B$1:$CW$1=$Q$10)+('0359-matrix'!$B$1:$CW$1=F13)+('0359-matrix'!$B$1:$CW$1=G13)+('0359-matrix'!$B$1:$CW$1=H13)+('0359-matrix'!$B$1:$CW$1=I13)+('0359-matrix'!$B$1:$CW$1=J13))*'0359-matrix'!$B$2:$CW$101)>0
I copied only last part, or when it starts from second row..Because it is too long to write whole funciton - it cuts down automatically.
('0359-matrix'!$B$1:$CW$1=$Q$10)+('0359-matrix'!$B$1:$CW$1=$B$13)+('0359-matrix'!$B$1:$CW$1=$C$13)+('0359-matrix'!$B$1:$CW$1=$D$13)+('0359-matrix'!$B$1:$CW$1=$E$13)+('0359-matrix'!$B$1:$CW$1=$F$13))*'0359-matrix'!$B$2:$CW$101)>0
But on marked cells I am getting the same results: B22 - F22 has the same as B21 - F21 (boolean) what shouldnt be like that but to follow color, green is False, it has to be something with an array reference.
Checkout the following. A1 to E5 is the matrix that shows which pieces are incompatible (=1). The others have to be empty or 0.
In cell I8 I used the following formula (and copied it down up to I11):
=SUMPRODUCT(($A$2:$A$5=H8)*(($B$1:$E$1=$H$8)+($B$1:$E$1=$H$9)+($B$1:$E$1=$H$10)+($B$1:$E$1=$H$11))*$B$2:$E$5)
The formula result shows you the amount of incompatibilities a part has. Eg AA1 has one incompatibility with BB2 but BB2 is incompatible with 2 AA1 and CC3.
To get the TRUE/FALSE use the same formula and append >0: like =SUMPRODUCT(…)>0
For any additinonal "group" (Model, Endpoint, …) you need to add another +($B$1:$E$1=$H$12) where $B$1:$E$1 points to your matrix data and $H$12 to your selected group value.
Overview of the formula ranges:
Note that this kind of calculation can only tell the amount of incompatibilites a part has but not the names of the parts that are incompatible.
Edited horizontal version
Formula in the selected cell is
=SUMPRODUCT(($A$2:$A$5=G8)*(($B$1:$E$1=$G$8)+($B$1:$E$1=$H$8)+($B$1:$E$1=$I$8)+($B$1:$E$1=$J$8))*$B$2:$E$5)
you can pull it to the right.

Index with double Match returns incorrect closest values

I have an planning exported to Excel which looks like the following (tab ' Data'):
Each production line has a number of people working on it. Now is my goal to show how many people are working on a line per minute. We plan per product group, and several product groups combined form waht a line has to do per minute.
To get the production per minute I created the following (tab 'Conversie'):
=INDEX(Data!$H$2:$H$157;MATCH($N$1&A4;Data!$B$2:$B$157&Data!$C$2:$C$157;1))
In the example it works correct. However, the formula doesn't seem to always return the correct "Artikelomschrijving"(H) every time. I get incorrect return values when I extend this formula to other product groups.
I read that the data needs to be sorted ascending cause I use match_type 1. When I do that I get the right returns for some product groups, but the given example suddenly returns incorrect values.
I can't sort both column C and A in ascending order for the formulas to always return correct items. Can you help me to get past this hurdle?
After a little bit of google translate work, if I'm understanding your question correctly, you need to find the "Item Description" (H) of the record where the "Line" (B) = the value in N1 and the time is between the start and end times.
This is an array formula, you have to confirm it with Ctrl+Shift+Enter
=INDEX(Data!$H$2:$H$157,MATCH(1,(Data!$B$2:$B$157=$N$1)*(Data!$C$2:$C$157<$A2)*(Data!$D$2:$D$157>=$A2),0))
OR with semicolon syntax:
=INDEX(Data!$H$2:$H$157;MATCH(1;(Data!$B$2:$B$157=$N$1)*(Data!$C$2:$C$157<$A2)*(Data!$D$2:$D$157>=$A2);0))
I found the solution, thank you for pointing me in the right direction Valon Miller. This is the formula I fixed it with:
=ALS.FOUT(INDEX(Data!$H$2:$H$154;MATCH(1;(Conversie!L$1=Data!$B$2:$B$154)*((Conversie!$A32>=Data!$C$2:$C$154)*(Conversie!$A32<=Data!$D$2:$D$154));0));"")

Indexing an answer limited to after today in Excel

I'm trying to put together a company excel sheet to keep track of the tickets we give out to senior sales to take out clients.
I put together a "Soonest Available Ticket" section to easily ID what games are coming up we still have tickets for. However, we don't give out tickets to every game and so I want to have these formulas return dates only of games that have not happened yet. Right now, they simply return the first unclaimed game which are all in the past.
I've tinkered with a few formulas, but I can't figure out how to only command it to look at dates today or later. Any ideas?
Below, in order, are my original Index formula, and then my attempts to only find upcoming games.
=IFERROR(INDEX(CubsDate,MATCH("Avail*",CubsTicketStatus,0),1),"Filled")
=IF(WhiteSoxDate>NOW(),IFERROR(INDEX(WhiteSoxDate,MATCH("Avail*",WhiteSoxTicketStatus,0),1),"Filled"),"Season Ended")
=IF(WhiteSoxDate>NOW(),INDEX(WhiteSoxDate,MATCH("Avail*",WhiteSoxTicketStatus,0),1),"Season Ended")
{=INDEX(WhiteSoxDate,(MATCH("Av*"&"*">TODAY(),WhiteSoxTicketStatus&WhiteSoxDate,0)))}
Assuming that "CubsDate" and "CubsTicketStatus" are named ranges of cells (the former containing dates and the latter the status, either "Avail" or "Filled"), then perhaps this will do what you want:
{=INDEX(CubsDate,MATCH(1,(CubsTicketStatus="Avail")*(CubsDate>TODAY()),0))}
Note that if there is no matching date after the current date, you'll get an #N/A result (which you could easily test for).
Here's a test I ran:
Note that the data here is in rows 25 - 31. Also, you'll need to format the result as a date.
Hope this helps!
Edit: Here's an explanation of how the Match function is being used. (I edited the answer so that future generations will find it more easily than if I added a comment.)
As a reminder (because I'm old and forgetful), the Match function takes three parms: Lookup Value, Lookup Array, and Match Type. So in
MATCH(1,(CubsTicketStatus="Avail")*(CubsDate>TODAY()),0)
we're looking for a value of 1 with a match type of 0 (exact match). That's the easy part. Our Lookup Array, however, is a little more complex. It consists of two tests multiplied by each other. So in each row, it looks at the value in CubsTicketStatus to see if it is "Avail" and it looks at the value in CubsDate to see if it's after today.
Each of those tests results in either TRUE or FALSE but, when you put them in the context of a mathematical calculation, they are 1 and 0. So if they're both TRUE, then you get 1 * 1, but if either (or both) is FALSE, you get zero. The Match function then returns the first row where both are TRUE -- that is, the first row where tickets are "Avail" and the date is after TODAY().

Ranking with subsets

I'm trying to rank values and have managed to work out how to sort ties. My data looks at the total number of entries, ranks based on that and if there is a tie it looks to the next column of values to sort them out. However, I have two classes (East and West I've called them) of data within my dataset and want to rank them both separately (but stick to the rules above). So, if I had seven entries, 3 of them West and 4 of the East, I want West to have ranking 1,2,3 based on all the values that lie in that subset and East would have ranking 1,2,3,4. Can you explain what your formula is doing so I can understand how to apply your answer better in the future.
Effectively I'm asking what formula needs to go in achieve my result.
Cheers
Paul
There are a few related ways to do this, most involving SUMPRODUCT. If you don't like the solution below and would like to research other ways/explanations, try searching for "rankif".
The function looks up the Class and Value columns and, for every value in those columns, returns a TRUE or 1 if the current Class is a match AND if its Value is larger than the current Value, False or 0 if otherwise. The SUM adds up all these 1s, and the 1+ is for decoration. Remember to enter as an array formula using Ctrl+Shift+Enter before dragging down.
I used the array formula and SUM above to explain, but the following also works and might even be faster since it's not an array formula. It's the same idea, except we hijack SUMPRODUCT's ability to spit out a single value from an array.
=1+SUMPRODUCT(($A$2:$A$8=A2)*($B$2:$B$8>B2))
EDIT
To extend the rank-if, you could add more subsets to rank by multiplying more conditions:
You can also easily add tiebreakers by adding another SUMPRODUCT to treat the ties as an additional subset:
The first SUMPRODUCT is the 'base rank', while the second SUMPRODUCT is tiebreaker #1.

In Excel, how can i break ties when ranking students' tests?

I'm doing like a bit of a competition for my students in which they have a weekly test they have to complete and submit. The grade is stored in an excel column next to their names.
Following instructions i found, i was able to create a full working general TOP3 with the Average of the tests' grade and when i get to the TOP5 for the grades of the last submitted test, i get a three-way tie.
I use the LARGE function to find the top grades and the combination of the INDEX and MATCH functions to find and display the name associated to that mark.
(Something like this =INDEX($A$1:$A$29;MATCH(M12;$F$1:$F$29;0))
The problem is that the function compares the grade on it's left to find that value in the range of grades and then returns the corresponding name associated to that row; so, it returns the same name for the three grades.
I tried using an IF function to exclude the first-result-cell from the array in which the formula is looking so that when it finds a match it will be different from the previous one, but i have not manage to work it out...
You need to use a pivot table and filter the results to the top 3. A pivot table will display the ties.
Here is a link that #Jeeped gave which basically solves the problem!
Thank you all for commenting!
Multiple Ranked Returns from INDEX(…) with Duplicate Values:
http://tinyurl.com/naavhgf

Resources