Help with organising table

staceyalana

New Member
Joined
Sep 12, 2022
Messages
2
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,
I have a raw data table that has been exported from our system. What I need to do is organise the emergency contacts from this.
The raw data is as follows:
Column A = surname
Column B = first name
Column I = Emergency Contact (listed as 1st Emergency, 2nd Emergency, etc.)
Column J = emergency first name
Column K = emergency last name.

If the client has multiple contacts for the above, the client is duplicated.
Bloggs Joe, 1st Emergency, Joanne Bloggs
Bloggs Joe, 2nd Emergency, Joy Bloggs

What I need to do is create a new spreadsheet from the above in the following manner:
Rows headings:
Last name, first name, 1st Emergency Contact, 2nd Emergency Contact, etc.

and have the clients names in columns A and B, emergency contact names i.e.:

Surname First name 1st Emergency 2nd Emergency
Bloggs Joe Joanne Bloggs Joy Bloggs

I think I should be using an IF and/or VLOOKUP, but I cannot see to get the formula right.

I would appreciate any help with this.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I would do this with Power Query to merge the emergency contact names (first & last) and then pivot the table so that the emergency contacts appeared on the same row as the client. Once this is setup, changes in the source table will be reflected in the results table by executing Data > Refresh All > Refresh All. The following M code performs the transformation. This code is already set up in the file available below, although if column headings change the code will need some minor revisions.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Surname", "First Name", "Emergency Contact", "Emergency First Name", "Emergency Last Name"}),
    #"Merged Columns" = Table.CombineColumns(#"Removed Other Columns",{"Emergency First Name", "Emergency Last Name"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Emerg Contact Name"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[#"Emergency Contact"]), "Emergency Contact", "Emerg Contact Name"),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"1st Emergency", "1st Emergency Contact"}, {"2nd Emergency", "2nd Emergency Contact"}, {"Surname", "Last Name"}})
in
    #"Renamed Columns"
...producing this result:
Last NameFirst Name1st Emergency Contact2nd Emergency Contact
BloggsJoeJoanne BloggsJoy Bloggs
JonesJohnJudy JonesJessica Jones
SmithLeoJohn Garcia

...from this source table:
MrExcel_20220912_staceyalana.xlsx
ABCDEFGHIJK
1SurnameFirst NameColumn1Column2Column3Column4Column5Column6Emergency ContactEmergency First NameEmergency Last Name
2BloggsJoe1st EmergencyJoanneBloggs
3BloggsJoe2nd EmergencyJoyBloggs
4JonesJohn1st EmergencyJudyJones
5JonesJohn2nd EmergencyJessicaJones
6SmithLeo1st EmergencyJohnGarcia
Raw

If you are interested in exploring this option, the file I used is available here:
Let me know if you have any questions or need some help getting this running on your system.
 
Upvote 0
Solution
I would do this with Power Query to merge the emergency contact names (first & last) and then pivot the table so that the emergency contacts appeared on the same row as the client. Once this is setup, changes in the source table will be reflected in the results table by executing Data > Refresh All > Refresh All. The following M code performs the transformation. This code is already set up in the file available below, although if column headings change the code will need some minor revisions.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Surname", "First Name", "Emergency Contact", "Emergency First Name", "Emergency Last Name"}),
    #"Merged Columns" = Table.CombineColumns(#"Removed Other Columns",{"Emergency First Name", "Emergency Last Name"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Emerg Contact Name"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[#"Emergency Contact"]), "Emergency Contact", "Emerg Contact Name"),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"1st Emergency", "1st Emergency Contact"}, {"2nd Emergency", "2nd Emergency Contact"}, {"Surname", "Last Name"}})
in
    #"Renamed Columns"
...producing this result:
Last NameFirst Name1st Emergency Contact2nd Emergency Contact
BloggsJoeJoanne BloggsJoy Bloggs
JonesJohnJudy JonesJessica Jones
SmithLeoJohn Garcia

...from this source table:
MrExcel_20220912_staceyalana.xlsx
ABCDEFGHIJK
1SurnameFirst NameColumn1Column2Column3Column4Column5Column6Emergency ContactEmergency First NameEmergency Last Name
2BloggsJoe1st EmergencyJoanneBloggs
3BloggsJoe2nd EmergencyJoyBloggs
4JonesJohn1st EmergencyJudyJones
5JonesJohn2nd EmergencyJessicaJones
6SmithLeo1st EmergencyJohnGarcia
Raw

If you are interested in exploring this option, the file I used is available here:
Let me know if you have any questions or need some help getting this running on your system.
Thank you so much for your help, I would never have come up with that, and it was a lot easier as well.

I will have to explore this new option further if I have any more queries on the like.

Stacey
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,428
Members
448,961
Latest member
nzskater

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