0
votes

In one table I have two columns of linked Parent/Child data which I need to then Merge with a second table.

I need to create an Index column to obtain unique record so I can merge the two tables.

These tables have around 300 000 records each so I need to use Power Query and don't want to use Excel.

I need an index column based on the parent and then re=starts index count for every unique child

Parent   Child  Index needed
123      AAA     1
123      AAA     2
123      BBB     1
234      CCC     1
234      CCC     2
234      CCC     3

Table structure

1
Take a look at this articleRicardo Diaz

1 Answers

1
votes

If your initial table looks like:

Input table

then this code:

let
    initialTable = Table.FromColumns({{"123", "123", "123", "234", "234", "234"}, {"AAA", "AAA" , "BBB", "CCC", "CCC", "CCC"}}, type table [Parent = text, Child = text]),
    grouped = Table.Group(initialTable, {"Parent", "Child"}, {{"toCombine", each Table.AddIndexColumn(_, "Index", 1, 1), type table}}),
    combined = Table.Combine(grouped[toCombine])
in
    combined

should give expected output:

Output table