Question about excel columns csv file how to combine columns - excel

I got a quick question I got a column like this
the players name and the percentage of matches won
Rank
Country
Name
Matches Won %
1 ESP ESP Rafael Nadal 89.06%
2 SRB SRB Novak Djokovic 83.82%
3 SUI SUI Roger Federer 83.61%
4 RUS RUS Daniil Medvedev 73.75%
5 AUT AUT Dominic Thiem 72.73%
6 GRE GRE Stefanos Tsitsipas 67.95%
7 JPN JPN Kei Nishikori 67.44%
and I got another data like this ACES PERCENTAGE
Rank
Country
Name
Ace %
1 USA USA John Isner 26.97%
2 CRO CRO Ivo Karlovic 25.47%
3 USA USA Reilly Opelka 24.81%
4 CAN CAN Milos Raonic 24.63%
5 USA USA Sam Querrey 20.75%
6 AUS AUS Nick Kyrgios 20.73%
7 RSA RSA Kevin Anderson 17.82%
8 KAZ KAZ Alexander Bublik 17.06%
9 FRA FRA Jo Wilfried Tsonga 14.29%
---------------------------------------
85 ESP ESP RAFAEL NADAL 6.85%
My question is can I make my two tables align so for example I want to have
my data based on matches won
So I have for example
Rank Country Name Matches% Aces %
1 ESP RAFAEL NADAL 89.06% 6.85%
Like this for all the player

I agree with the comment above that it would be easiest to import both and to then use XLOOKUP() to add the Aces % column to the first set of data. If you import the first data set to Sheet1 and the second data set to Sheet2 and both have the rank in Column A , your XLOOKUP() in Sheet 1 Column E would look something like:
XLOOKUP(A2, Sheet2!A:A, Sheet2!D:D)

Related

Extract the mapping dictionary between two columns in pandas

I have a dataframe as shown below.
df:
id player country_code country
1 messi arg argentina
2 neymar bra brazil
3 tevez arg argentina
4 aguero arg argentina
5 rivaldo bra brazil
6 owen eng england
7 lampard eng england
8 gerrard eng england
9 ronaldo bra brazil
10 marria arg argentina
from the above df, I would like to extract the mapping dictionary that relates the country_code with country columns.
Expected Output:
d = {'arg':'argentina', 'bra':'brazil', 'eng':'england'}
Dictionary has unique keys, so is possible convert Series with duplicated index by column country_code:
d = df.set_index('country_code')['country'].to_dict()
If there is possible some country should be different per country_code, then is used last value per country.

Excel cell lookup in subtotaled range

I'd like to use index/match to lookup values in a subtotaled range. Using the sample data below, from another sheet (Sheet 2), I need to lookup the total NY Company hours for each employee.
Sheet 2:
| Bob | NY Company | ???? |
This formula returns the first match of NY Company Total
=INDEX('Sheet1!A1:C45,MATCH(Sheet2!B2 & " Total",'Sheet1!B1:B45,0),3)
Now I need to expand the lookup to include the Employee (Bob). Also, Column A is blank on the total Row. I've started to work with something like the following but no luck.
=INDEX('Sheet1!A1:C45,MATCH(1,('Sheet2!B2 & " Total"='Sheet1!B1:B45)*('Sheet2!B1='Sheet1!A1:A45)),3)
Also, as the sample data below looks perfect in the preview and then looks really bad after saving, I've added a pic with the sample data.
Sample data:
Sample Data:
A
B
C
Employee
Customer
Hours
Bob
ABC Company
5
Bob
ABC Company
3
ABC Company Total
8
Bob
NY Company
7
Bob
NY Company
7
Bob
NY Company
5
Bob
NY Company
3
NY Company Total
22
Bob
Jet Company
1
Jet Company Total
1
Carrie
ABC Company
1
Carrie
ABC Company
4
ABC Company Total
5
Carrie
NY Company
6
Carrie
NY Company
2
Carrie
NY Company
3
NY Company Total
11
Carrie
Jet Company
7
Carrie
Jet Company
9
Jet Company Total
16
Carrie
XYZ Company
4
XYZ Company Total
4
Gale
Cats Service
2
Gale
Cats Service
6
Gale
Cats Service
1
Cats Service Total
9
Gale
NY Company
6
Gale
NY Company
8
NY Company Total
14
Gale
XYZ Company
1
XYZ Company Total
1
John
NY Company
3
John
NY Company
5
NY Company Total
8
John
XYZ Company
8
John
XYZ Company
5
XYZ Company Total
13
Ken
ABC Company
10
ABC Company Total
10
Ken
NY Company
2
Ken
NY Company
3
Ken
NY Company
5
NY Company Total
10
Grand Total
132
Any suggestions??

Excel merge cells equivalent in SQL

I am trying to generate SQL output similar to how Excel does the merge cells.
Sample output from SQL select statement
Name
Country
State
years
lived
Alice
USA
CA
2
2
Alice
USA
NYC
1
1
Alice
USA
MI
5
5
Bob
USA
CA
1
1
Bob
USA
NYC
8
8
Bob
USA
IL
4
4
I am trying to convert the output in below format using SQL query, so I can directly export to Excel, instead of modifying in excel separately.
Name
Country
State
years
lived
CA
2
NYC
1
Alice
USA
MI
5
8
CA
1
NYC
8
Bob
USA
IL
4
13
Any help is appreciated.

Returning the last item in a subset with excel formula

In this example I would like to mark any customer that has bought a pen most recently(or bottom of the list). I have my data sorted by CustomerID and ServiceDate with the most recent as the last. I would like to be able to mark all of the customer’s transactions only if the last purchase was a pen (333).
I have been trying formulas with COUNTA but, not sure how to do it when relying on a subset of data.
=INDEX(C:C,COUNTA(C:C))
This will give me the last value in a column.
Customer ID Custmer Name Item Number Item Name Date Desired Results
1 Bob 222 Paper 1/1/2016 X
1 Bob 111 Tape 1/1/2017 X
1 Bob 333 Pen 1/1/2018 X
4 Greg 333 Pen 1/1/2015
4 Greg 111 Tape 1/1/2016
6 Chris 111 Tape 1/1/2015 X
6 Chris 333 Pen 1/1/2018 X
8 Luke 333 Pen 1/1/2013
8 Luke 333 Pen 1/1/2014
8 Luke 222 Paper 1/1/2015
8 Luke 111 Tape 1/1/2016
8 Luke 111 Tape 1/1/2018
9 Tom 333 Pen 1/1/2013 X
You can do this by creating an additional column. The additional column will find all customers whose last purchase was a pen using this formula: =IF(AND(C2=333,B2<>B3),B2,"").
The next column will give you your desired output: =IF(OR(B2=$F$4,B2=$F$8,B2=$F$14),"X","").
Thanks to joe I was able to figure this one out.
I still had to make another column.
I put this in column F.
=IF(AND(C2=333,B2<>B3),1,"")
Then in column G.
=IF(AND(COUNTIFS(A:A,A2,F:F,1)=1),"Yes","")
This worked great.

MAX of mapped criteria unless another value is lower

I asked this question in the past. What I need to do now is List Dan's Bakery in the Entity final column. The original entities go through a mapping table and the MAX limit is in the Limit final column. Here is that formula, {=MAX(IF(ISNUMBER(MATCH($G$2:$G$110,IF('Mapping Table'!$B$4:$B$204=B25,'Mapping Table'!$A$4:$A$204),0)),$D$2:$D$110))}. In the above formula, the lookup value for Match is the Parent Connection (G) column and the mapping table maps any entities with certain names to a parent and the D column would be the Limit 1 as there is a hidden column. Hope that's clear enough.
I want to now write a similar formula so that whichever Entity has the highest limit and WORST risk rating is shown in the Entity final column. Meaning, in the below example, Dan's Groceries would be the entity I want to produce in the Entity final column because it has a credit limit line of 30 and a better rating (the lower the rating, the better). Any ideas?
EDIT (March 21) : I need a formula that will take into account the mapping it will register the above formula as well as take into the account the ratings.
I changed the formula to,
=INDEX($A$1:$A$7,MATCH(MIN((1-IF($B$1:$B$7=B1,$D$1:$D$7)/MIN(IF($B$1:$B$7=B1,$D$1:$D$7)))+IF($B$1:$B$7=B1,$C$1:$C$7)/MAX(IF($B$1:$B$7=B1,$C$1:$C$7))),(1-$D$1:$D$7/MIN(IF($B$1:$B$7=B1,$D$1:$D$7)))+IF($B$1:$B$7=B1,$C$1:$C$7)/MAX(IF($B$1:$B$7=B1,$C$1:$C$7)),0))
but, I am coming across errors. For example, if I changed the Limit column for Other to 30, Dan's Bakery is the result or when I change Dan's Shakes limit to 40 (assuming it will be the correctFinal Entityit seems to be taking the MIN rating as the ultimate decider withDan's Fuel` still as the result.
So if your Limit and Rating worth the same you can scale them to values between 0 and 1. After that simple addition would rate one of Entities as the "winner".
Here is example data and an array formula that can do what you want(Array Formulas are applied with Ctrl + Shift + Enter:
Data:
A B C
Dan's Shakes 25 3
Dan's Groceries 30 2
Dan's Floral 10 2
Dan's Bakery 30 1
Dan's Fuel 20 4
Formula:
=INDEX(A1:A5,MATCH(MAX((1-C1:C5/MAX(C1:C5))+B1:B5/MAX(B1:B5)),(1-C1:C5/MAX(C1:C5))+B1:B5/MAX(B1:B5),0))
Outcome:
A B C D
Dan's Shakes 25 3 Dan's Bakery
Dan's Groceries 30 2
Dan's Floral 10 2
Dan's Bakery 30 1
Dan's Fuel 20 4
EDIT:
And when you introduce a parent your data would look like this:
A B C D
Dan's Shakes Dan Corp 25 3
Dan's Groceries Dan Corp 30 2
Dan's Floral Dan Corp 10 2
Dan's Bakery Dan Corp 30 1
Dan's Fuel Dan Corp 20 4
Something Else Bob Corp 30 2
Other Bob Corp 50 1
Your array formula:
=INDEX($A$1:$A$7,MATCH(MAX((1-IF($B$1:$B$7=B1,$D$1:$D$7)/MAX(IF($B$1:$B$7=B1,$D$1:$D$7)))+IF($B$1:$B$7=B1,$C$1:$C$7)/MAX(IF($B$1:$B$7=B1,$C$1:$C$7))),(1-$D$1:$D$7/MAX(IF($B$1:$B$7=B1,$D$1:$D$7)))+IF($B$1:$B$7=B1,$C$1:$C$7)/MAX(IF($B$1:$B$7=B1,$C$1:$C$7)),0))
Result:
A B C D E
Dan's Shakes Dan Corp 25 3 Dan's Bakery
Dan's Groceries Dan Corp 30 2 Dan's Bakery
Dan's Floral Dan Corp 10 2 Dan's Bakery
Dan's Bakery Dan Corp 30 1 Dan's Bakery
Dan's Fuel Dan Corp 20 4 Dan's Bakery
Something Else Bob Corp 30 2 Other
Other Bob Corp 50 1 Other

Resources