Excel Split each row in a group into multiple rows according to the specified rule

In the Excel table below, column A is the grouping column and column B contains strings separated by ">". Values in column B can be seen as the concatenated detail data:


A

B

1

ID

Rule: Condition

2

470210642217

Test

3

470251569449

Doors & Hardware > Door Jambs> 119mm

4

470251602217

Bathroom > Stone Tops > Black Specs> 1200mm

The task is to split each row into multiple rows. The rule is this: keep values of column A unchanged; split each value in column B into detail data items and concatenate them in a cumulative way:


A

B

7

ID

Rule: Condition

8

470210642217

Test

9

470251569449

Doors & Hardware

10

470251569449

Doors & Hardware > Door Jambs

11

470251569449

Doors & Hardware > Door Jambs> 119mm

12

470251602217

Bathroom

13

470251602217

Bathroom > Stone Tops

14

470251602217

Bathroom > Stone Tops > Black Specs

15

470251602217

Bathroom > Stone Tops > Black Specs> 1200mm

Use SPL XLL to enter the formula below:

=spl("=?.conj(~(2).split("">"").(~=~[-1] | ~).(~.concat("">"")).([?.~(1),~]))",A2:B4)

Picture1png

The conj()function concatenates the subsets; split() function splits a string into a set; and concat()function concatenates members of a set into a string. ~ represents the current member, ~[-1] references the directly previous members and | calculates union.

Source:https://stackoverflow.com/questions/78382496/split-text-into-smaller-one-and-group-by-each-id