1

I have the following simplified data set which I need to create a unique list from and transpose the data from column B at the same time. I think I need to use INDEX, but I am unsure on the correct syntax for this scenario.

The data in column B is delimited by a space.

This is what my data looks like:

|---------------------|------------------|
|      Column A       |      Column B    |
|---------------------|------------------|
|          1          |       AA BB      |
|---------------------|------------------|
|          2          |       BB CC      |
|---------------------|------------------|
|          3          |       DD EE      |
|---------------------|------------------|

Required result

|---------------------|------------------|
|      Column A       |      Column B    |
|---------------------|------------------|
|          1          |         AA       |
|---------------------|------------------|
|          1          |         BB       |
|---------------------|------------------|
|          2          |         BB       |
|---------------------|------------------|
|          2          |         CC       |
|---------------------|------------------|
|          3          |         DD       |
|---------------------|------------------|
|          3          |         EE       |
|---------------------|------------------|
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
user3580480
  • 442
  • 7
  • 14
  • 45

2 Answers2

1

To get your output table given your input table, you can use Power Query, from the UI, in just a few steps:

  • Split Column B by the space delimiter.
  • Select Column A and then select to unpivot other columns
  • Delete the extra column Attribute that appears when you unpivot.

This is the M code for that operation

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column2", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Column2.1", "Column2.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column2.1", type text}, {"Column2.2", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Column1"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"})
in
    #"Removed Columns"

And the results:

enter image description here

Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
0

Ron Rosenfeld's answer unpivots the data as the OP indicated by the required result.

If you need to create all combinations of data from two columns (rather than unpivoting), normalize the data by placing each set of values in its own column. In this example, Column B has two data entries per cell, which can be split using Data > Text to Columns. To work with unique entries, either use the standard Excel tool Data > Remove Duplicates, or in Excel Power Query Editor, right click the data column header and click Remove Duplicates.

Create separate queries for each column to be included in the combinations. By adding a custom column with a formula referring to the first data query, Power Query will perform a Full Outer Join across the two columns resulting in all combinations.

Final Table Result

Final data table


Step 1: Data > Text to Columns

(a) Select Column B. In the ribbon, go to Data > Text to Columns.

Excel data table

Data > Text to Columns


(b) Split the data on the appropriate delimiter (Space, Tab, etc.).

Select delimiter


Step 2: Combine data and remove duplicates

(a) Cut data from Column C and paste into Column B

Three columns of data

(b) Paste Column C data into Column B.

Combined column data

(c) Select Column B and then click Data > Remove Duplicates

Remove duplicates

(d) If warning pops up about data found next to selection, click "Continue with the current selection"

Remove duplicates warning

(e) Select checkbox for Column B and click OK.

Select columns to remove duplicates

Step 3: Create data query for Column A

(a) Select Column A and click Data > From Table/Range

Data - From Table/Range

(b) Query Settings > PROPERTIES > Name and enter name "ColumnA"

(c) Home > Close & Load > Close & Load To...

(d) Select: Only Create Connection

Query Settings - enter name

Step 4: Create data query for Column B

(a) Select Column B

(b) Data > From Table/Range

Column B data query

(c) Query Settings > PROPERTIES > Name and enter name "ColumnB"

(d) Add Column > Custom Column

Add Column > Custom Column

(e) New column name: Combinations

(f) Custom column formula: =ColumnA

Custom column formula

(g) Expand the new "Combinations" column (icon with left/right arrows)

Expand new Combinations column

(h) Drag the "Combinations" column to the left side

(i) Home > Close & Load

Step 5: Sort the output data table

Sort data

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117