Approach to sorting and index/match

RonOliver

Board Regular
Joined
Aug 30, 2022
Messages
99
Office Version
  1. 365
Platform
  1. Windows
Hi.
Let me paste these two sheets:

Sheet1...
Book1
ABCD
1FIRST NAMELAST NAMEID NUMBERE-MAIL
2MichaelWalker123456789mike@gmail.com
3SarahWalker234567891walker.sarah@gmail.com
4JohnTimmons345678912john@gmail.com
5AshleyBjornsdottir456789123bjorn@gmail.com
6AndrewWest567891234west@hotmail.com
7LesJohnson678912345johnson@hotmail.com
Sheet1


and Sheet2...

Cell Formulas
RangeFormula
A2:A7A2=IF(AND(ISBLANK(Sheet1!A2:A7)),"",PROPER(SORT(FILTER(Sheet1!B2:B7,Sheet1!B2:B7<>""))))
B2:B7B2=IFERROR(PROPER(INDEX(Sheet1!$A$2:$A$7,MATCH(A2,Sheet1!$B$2:$B$7,0))),"")
C2:C7C2=IFERROR(PROPER(INDEX(Sheet1!$C$2:$C$7,MATCH(A2,Sheet1!$B$2:$B$7,0))),"")
D2:D7D2=IFERROR(PROPER(INDEX(Sheet1!$D$2:$D$7,MATCH(A2,Sheet1!$B$2:$B$7,0))),"")
Dynamic array formulas.


The second swaps first and last name and sorts everything by last name. However, by using index/match, if two people have the same last name, I'm only getting the first instance where it matches. Can you please let me know if you would try a different approach? This is a reduced version of my sheet, which has a lot more columns, so not all approaches will work. I'm just asking if there's something I'm doing fundamentally wrong.

Thanks everyone!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
A power query means to the end

Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    T2 = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    MQ = Table.NestedJoin(T2, {"LAST NAME"}, T1, {"LAST NAME"}, "Table2", JoinKind.FullOuter),
    ET = Table.ExpandTableColumn(MQ, "Table2", {"FIRST NAME", "LAST NAME", "ID NUMBER", "E-MAIL"}, {"FIRST NAME", "LAST NAME.1", "ID NUMBER", "E-MAIL"}),
    RC = Table.RemoveColumns(ET,{"LAST NAME"}),
    RD = Table.Distinct(RC, {"FIRST NAME", "LAST NAME.1"})

in
    RD
 
Upvote 0
Since you are already using Filter & Sort the output is going to be a dynamic array, so why not keep going with that approach ? See below.

Book1
ABCD
1LAST NAMEFIRST NAMEDATE OF BIRTHE-MAIL
2BjornsdottirAshley456789123Bjorn@Gmail.Com
3JohnsonLes678912345Johnson@Hotmail.Com
4TimmonsJohn345678912John@Gmail.Com
5WalkerMichael123456789Mike@Gmail.Com
6WalkerSarah234567891Walker.Sarah@Gmail.Com
7WestAndrew567891234West@Hotmail.Com
Sheet2
Cell Formulas
RangeFormula
A2:D7A2=PROPER(CHOOSECOLS(SORTBY(FILTER(Sheet1!A2:D7,Sheet1!B2:B7<>""),Sheet1!B2:B7,1,Sheet1!A2:A7,1),2,1,3,4))
Dynamic array formulas.
 
Upvote 0
Since you are already using Filter & Sort the output is going to be a dynamic array, so why not keep going with that approach ? See below.

Book1
ABCD
1LAST NAMEFIRST NAMEDATE OF BIRTHE-MAIL
2BjornsdottirAshley456789123Bjorn@Gmail.Com
3JohnsonLes678912345Johnson@Hotmail.Com
4TimmonsJohn345678912John@Gmail.Com
5WalkerMichael123456789Mike@Gmail.Com
6WalkerSarah234567891Walker.Sarah@Gmail.Com
7WestAndrew567891234West@Hotmail.Com
Sheet2
Cell Formulas
RangeFormula
A2:D7A2=PROPER(CHOOSECOLS(SORTBY(FILTER(Sheet1!A2:D7,Sheet1!B2:B7<>""),Sheet1!B2:B7,1,Sheet1!A2:A7,1),2,1,3,4))
Dynamic array formulas.
Tried this but it doesn't work. Also, I'd like some cols to be UPPER() and some others to be LOWER(). There might also be gaps in the table (someone's e-mail missing, for example), so I don't know if that approach would work. Thanks anyway!
 
Upvote 0
You didn't say it doesn't work because you want different columns treated differently, so what does doesn't work mean ?
It worked fine on your sample.
 
Upvote 0
A power query means to the end

Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    T2 = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    MQ = Table.NestedJoin(T2, {"LAST NAME"}, T1, {"LAST NAME"}, "Table2", JoinKind.FullOuter),
    ET = Table.ExpandTableColumn(MQ, "Table2", {"FIRST NAME", "LAST NAME", "ID NUMBER", "E-MAIL"}, {"FIRST NAME", "LAST NAME.1", "ID NUMBER", "E-MAIL"}),
    RC = Table.RemoveColumns(ET,{"LAST NAME"}),
    RD = Table.Distinct(RC, {"FIRST NAME", "LAST NAME.1"})

in
    RD
I'm not familiar with power queries. Will this work on Excel online?
 
Upvote 0
You didn't say it doesn't work because you want different columns treated differently, so what does doesn't work mean ?
It worked fine on your sample.

I tried copying and pasting, trying to make it fit, but it returned a #VALUE! error for some reason. I don't know why.

I guess, because some columns need to have a different behavior, I need to use different formulas for each column, which was my original approach. I'm afraid that's something I didn't say at the beginning, because I didn't realize it was very important. Having gaps (missing e-mail, missing ID, etc.) is only going to make things more complicated when sorting, but I'm not very well versed in Excel, so I don't know.
 
Upvote 0
Handling one issue at a time does it work if you use this:
Excel Formula:
=PROPER(CHOOSECOLS(FILTER(SORTBY(Sheet1!A2:D7,Sheet1!B2:B7,1,Sheet1!A2:A7,1),Sheet1!B2:B7<>""),2,1,3,4))
 
Upvote 0
Handling one issue at a time does it work if you use this:
Excel Formula:
=PROPER(CHOOSECOLS(FILTER(SORTBY(Sheet1!A2:D7,Sheet1!B2:B7,1,Sheet1!A2:A7,1),Sheet1!B2:B7<>""),2,1,3,4))
This would work if none of the cells were blank, but there might be blank cells.
 
Upvote 0

Forum statistics

Threads
1,223,836
Messages
6,174,923
Members
452,592
Latest member
Welshy1491

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top