Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Zoombini
Regular Visitor

Expanding Tables After Grouping

I'm having some difficulty getting some XML based data into a usable format. After a little cleanup it looks like this:

BI1.PNG

 

The red line shows the cutoff where they start repeating. Ultimately I'd like to group these and use them as my columns. After grouping it looks like this:

 

 

BI2.PNGBI3.PNG

 

I need a way to expand those tables into their own columns using just the data columns from each table. Then I can transpose the whole thing and have a functional data set. Any help is appreciated.

1 ACCEPTED SOLUTION

My suggestion would be another approach.

 

Based on your first table, if each group consists of 28 rows, than you can add an Index column starting with 0, transform this index column using (Transform - Standard - Integer-divide) by 28, and now you can pivot on the first column.

 

Alternatively, if your groups have a variable number of items (not always 28), but they always start with "Order Date", after adding the Index column you can add another column with formula = if [Columns] = "Order Date" then [Index] else null.

Fill down this new column, so each group of data will have its own number (the same number within each group).

Remove the original Index column and now you can pivot on the first column.

 

Edit: in both scenarios, you can remove the added column after pivoting.

 

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Zoombini,

 

For your requirement, you can add custom column with 'list.contains' and 'table.columnnames' functions to check if current table contains date column. Then expand the correspond records.

 

Steps:

 

1.  Add custom column to get specific column from table.

#"Added Custom" = Table.SelectRows(Table.AddColumn(#"Removed Other Columns", "Custom", each if List.Contains(Table.ColumnNames([Data]),"Date") then [Data][Date] else null),each [Custom] <> null),

9.PNG

 

2. Expand column item to new row.

10.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

My suggestion would be another approach.

 

Based on your first table, if each group consists of 28 rows, than you can add an Index column starting with 0, transform this index column using (Transform - Standard - Integer-divide) by 28, and now you can pivot on the first column.

 

Alternatively, if your groups have a variable number of items (not always 28), but they always start with "Order Date", after adding the Index column you can add another column with formula = if [Columns] = "Order Date" then [Index] else null.

Fill down this new column, so each group of data will have its own number (the same number within each group).

Remove the original Index column and now you can pivot on the first column.

 

Edit: in both scenarios, you can remove the added column after pivoting.

 

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.