Returning the last item in a subset with excel formula - 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.

Related

Question about excel columns csv file how to combine columns

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)

How do I create single cell arrays based on unique contiguous groups?

Column A identifies unique families using multiple other columns of data.
Column B is a list of individuals.
I would like Column C to contain cell arrays of these families (Shown Below).
For some reason, the MATCH formula in my attempted solution is returning the last occurrence of the match, so it does not work.
I have tried this formula (the output of this is shown in Column D in the picture):
{=OFFSET(INDEX(A:A, MATCH(A1,A:A)),0,1,COUNTIF(A:A,A1))}
A B C D
1 Tom 1 {Tom One, Sue One} Sue 1
1 Sue 1 {Tom One, Sue One} Sue 1
2 Bob 2 {Bob Two, Joan Two, John Two} John 2
2 Joan 2 {Bob Two, Joan Two, John Two} John 2
2 John 2 {Bob Two, Joan Two, John Two} John 2
3 Tom 3 {Tom Three} Tom 3
4 Joe 4 {Joe Four} Joe 4
You can use the following formula, the condition is that it is sorted baed on column A:
="{"&TEXTJOIN(",",TRUE,INDEX(B:B,MATCH(A1,A:A,0)):INDEX(B:B,MATCH(A1,A:A,1)))&"}"

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

Combine 2 different sheets with same data in Excel

I have the same data from different sources, both incomplete, but combined they may be less incomplete..
I have 2 files;
File #1 has; ID, Zipcode, YoB, Gender
File #2 has: Email, ID, Zipcode, Yob, Gender
The ID's in both files are the same, but #1 has some ID's that #2 hasn't, and the other way aroud.
The Email is connected to the ID. ID's are linked to the zipcode, YoB and gender. In both files are some of that info missing. E.g. File #1 and #2 both have ID 1234, only in #1 it only has a postal code, YoB but no Gender. And #2 has the zipcode and gender but no YoB.
I want to have all the information in one file;
Email, ID, YoB, Zipcode, Gender
I tried to sort both ID's alphabetically and put them next to each other and search for duplicates, but because #1 has some ID's that #2 doesnt I'm not able to combine them...
What's the best way to fix this?
By the way its about 12000 ID's from #1 and 9500 from #2
If you want a list of all the unique IDs then you could create a new sheet, copy both lots of IDs into the same column and then use Advanced Filter to copy Unique records only to another column.
Then use that column to do vlookups from the two files in the columns you require.
(I'm presuming this is a one-time job and you don't mind a bit of manual-ness)...
If on your first Sheet ("Sheet1") you have:
ID F_Name S_Name Age Favourite Cheese
1 Bob Smith 25 Brie
2 Fred Jones 29 Cheddar
3 Jeff Brown 18 Edam
4 Alice Smith 39 Mozzarella
5 Mark Jones 65 Cheddar
7 Sarah Smith 29 Mozzarella
8 Nick Jones 40 Brie
10 Betty Thompson 34 Edam
and on your second Sheet ("Sheet2") you have:
ID F_Name S_Name Age
1 Bob Smith 25
3 Jeff Brown 18
4 Alice Smith 39
5 Mark Jones 65
6 Frank Brown 44
7 Sarah Smith 29
9 Tom Brown 28
10 Betty Thompson 34
Then if you're combining them on a 3rd Sheet you need to do something like:
=IFERROR(VLOOKUP($A2,Sheet1!$A$1:$E$9,COLUMN(),FALSE),VLOOKUP($A2,Sheet2!$A$1:$E$9,COLUMN(),FALSE))
If you're trying to get to:
ID F_Name S_Name Age Favourite Cheese
1 Bob Smith 25 Brie
2 Fred Jones 29 Cheddar
3 Jeff Brown 18 Edam
4 Alice Smith 39 Mozzarella
5 Mark Jones 65 Cheddar
6 Frank Brown 44 0
7 Sarah Smith 29 Mozzarella
8 Nick Jones 40 Brie
9 Tom Brown 28 0
10 Betty Thompson 34 Edam

Get Top Performer by Subgroup Using Index and Match

I am trying to rank names in Column C from largest to smallest score.
Category Score Name Total Rank Apple Rank Orange Rank
Apple 10 Joe Rachel Rachel 0
Orange 15 Don Natalie 0 Natalie
Apple 20 James Tom Tom 0
Apple 1 Rob Nothing Nothing 0
Orange 3 Mary Gina 0 Gina
Orange 100 Rachel James 0 James
Orange 99 Natalie Don 0 Don
Orange 87 Tom Joe 0 Joe
Apple 27 Gina Mary Mary 0
Orange 30 Nothing Rob 0 Rob
This works in Column E for Apples AND Oranges, with formula in E2 that is
=INDEX($C$2:$C$25,MATCH(1,INDEX(($B$2:$B$25=LARGE($B$2:$B$25,ROWS(E$1:E1)))*(COUNTIF(E$1:E1,$C$2:$C$25)=0),),0))
However, the goal is to compare Apples to Apples and Oranges to Oranges.
Only, the formulas in Columns F and G show "0" values for those rows that aren't in the right Apple/Orange category.
For F2:
=IF($A:$A="Apple",INDEX($C:$C,MATCH(1,INDEX(($B:$B=LARGE($B:$B,ROWS(F$1:F1)))*(COUNTIF(F$1:F1,$C:$C)=0),),0)),0)
For G2:
=IF($A:$A="Orange",INDEX($C:$C,MATCH(1,INDEX(($B:$B=LARGE($B:$B,ROWS(G$1:G1)))*(COUNTIF(G$1:G1,$C:$C)=0),),0)),0)
How do I modify the codes so that 0 values won't show up?
Something like this would be great: (screenshot made by just copy pasting values...)
Apple Rank Orange Rank
Rachel Natalie
Tom Gina
Nothing James
Mary Don
Joe
Rob
Note: Unless the whole column ranges are required the steps below may seem to take an uncomfortably long time if these ranges are not restricted.
Assuming you have what below is in ColumnA:G and a corresponding layout:
then ColumnsI:J may be achieved quite simply by copying ColumnF:G and Paste Special..., Values into I1, then select ColumnsI:J, HOME > Editing - Find & Select, Replace..., Find what: 0, Replace with: , Replace All followed by Find & Select, Go To Special..., select Blanks (only), OK, right-click on one of the chosen cells and Delete..., Shift cells up, OK.
To remove the 0s from ColumnF:G only replacing the final 0 in each formula with "" is sufficient.

Resources