LOOKUP reference with mulitple outcome values

0

I am looking to pull out and display the multiple ages of people associated with a single reference number.

Below snipped displays the sheet set up. The sheet has approximate 2500 rows:

App ref,Relationship,Age,Date of Birth,Gender,Marital Status
1,A1,34,12-Apr-85,F,SINGLE
1,A1,34,12-Apr-85,F,SINGLE
1,PT,30,12-Oct-89,M,SINGLE
830,A1,63,10-Nov-56,F,MARRIED
830,SN,32,11-Nov-87,M,SINGLE
830,HU,65,24-Sep-54,M,MARRIED
846,A1,75,11-Aug-44,M,MARRIED
846,A2,72,16-Nov-47,F,MARRIED

For each App Ref, I want to pull out all associated ages:

| App ref | Age 1 | Age 2 | Age 3 |
|---------|-------|-------|-------|
| 1       |  34   |  34   |  30   |
| 830     |  63   |  32   |  65   |
| 846     |  75   |  72   |  -    |

Ross

Posted 2019-07-01T10:22:48.573

Reputation: 1

how many different ages could there be ? is it always 3 as per example ? – PeterH – 2019-07-01T10:52:41.213

1Hi Ross and welcome to Superuser. Help us help you: don't post your example data from a spreadsheet as an image. I can't copy paste that into me Excel and create a solution for you. – Saaru Lindestøkke – 2019-07-01T11:02:44.633

Answers

0

  1. Copy column A to an unused column where your target data will start and use Data, Remove Duplicates to generate a set of unique App ref numbers. In my sample image below, I've used column H.
  2. Put this formula in the row 1 cell immediately to the right of your unique App ref numbers and drag it right. In my sample, I've started in I1.

    =TEXT(COLUMN(A:A), "\A\g\e 0")
    
  3. Put this formula under Age 1 and drag right and down. In my sample, I've started in I2.

    =IFERROR(INDEX($C:$C, AGGREGATE(15, 7, ROW($C$2:INDEX($C:$C, MATCH(1E+99, $C:$C)))/($A$2:INDEX($A:$A, MATCH(1E+99, $C:$C))=$H2), COLUMN(A:A))), "")
    

enter image description here

If the App ref column is sorted ascending then you can reduce calculation by limiting the lookup rows.

=IFERROR(INDEX($C:$C, AGGREGATE(15, 7, ROW(INDEX($A:$A, MATCH($H2, $A:$A, 0)):INDEX($A:$A, MATCH($H2, $A:$A))), COLUMN(A:A))), "")

Jeeped

Posted 2019-07-01T10:22:48.573

Reputation: 2 435

0

You can do this easily with Power Query a free add-in from Microsoft in Excel 2010+; included as Get & Transform in Excel 2016+

Except for entering the custom column formula, everything can be done from the GUI, and if your original data changes, the query is easily refreshed.

  • Select a cell in your original table
  • Data--> Get & Transform --> from Table/Range
  • Group by App ref operation == All Rows

enter image description here

  • Add Custom Column (to change the Age column into a List
    • Formula =Table.Column([Merged],"Age")
  • Right click on the double arrow of this new Custom column and choose to Extract the values using comma as the separator
  • Split the column using comma as the separator.
  • Rename the new columns to Age n etc
  • Close and Load the results

M-Code

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"App ref", Int64.Type}, {"Relationship", type text}, {"Age", Int64.Type}, {"Date of Birth", type datetime}, {"Gender", type text}, {"Marital Status", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"App ref"}, {{"Merged", each _, type table [App ref=number, Relationship=text, Age=number, Date of Birth=datetime, Gender=text, Marital Status=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Merged],"Age")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Custom.1", Int64.Type}, {"Custom.2", Int64.Type}, {"Custom.3", Int64.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Custom.1", "Age 1"}, {"Custom.2", "Age 2"}, {"Custom.3", "Age 3"}})
in
    #"Renamed Columns"

enter image description here

enter image description here

Ron Rosenfeld

Posted 2019-07-01T10:22:48.573

Reputation: 3 333