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
HYirang
New Member

Merge/Combine rows

I would like to combine several rows having same Key index like below. ID will be a unique ID of a product.

 

Table 'weird'

IDCategoryCate_ValueSizeColorPrice
ASize100100nullnull
AColorBluenullBluenull
APrice5000nullnull5000

 

For your informaiton, the original data set is first 3 columns. and i tried to solve the issue, I added 3 custom columns for each Category.

The result I want to make is like below. What I want is similar with remove duplicate. but all data of column should be reserved.

IDCategoryCate_ValueSizeColorPrice
Aanythinganything100Blue5000

 

 

For your understaing, please see the detail situation and my final goal.

1. first, I know the original data is suck. but I can't change it as it is loaded from online which I can't edit.

2. There are serveral other tables having unique ID like below

Table 'Normal'

IDBuyerProducerCreated
AOliviaKevin10-Jul

 

3. I can make some relation and report like below using 'Normal' table.

Producer - Color

Created date - Size

Sum of products per producer

sold Qty to Olivia by Kevin

etc...

 

But I can't get the result between the attributes in table 'weird'.

- Total numbers of speific color per speicifc size.

- Sum of the price for specific size or color

 

hope you understand this.

ny small hints can help.

 

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hi , @HYirang 

You don't need to  added 3 custom columns for each Category.

Just select the column "Category" and use the function pivot column

1.png

2.PNG

 

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

mahoneypat
Employee
Employee

You can use this M query approach to prep your data for a better model.  I put your example "weird" data in, kept the first 3 columns, and then unpivot (w/o aggregation) to get your desired result.  With that table, you can easily make relationships with your other "normal" tables on the ID column and do basic SUM() and COUNT() type measures.

 

To see the steps, just paste this M code into a blank query, click on Advanced Editor and replace the text there with this:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQrOrEoFUoYGBnAyrzQnB0bF6kCUOefn5BcBaaec0lSEEmQeTGVAUWYySNDUAMMwqGBsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Category = _t, Cate_Value = _t, Size = _t, Color = _t, Price = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Category", type text}, {"Cate_Value", type text}, {"Size", Int64.Type}, {"Color", type text}, {"Price", Int64.Type}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"ID", "Category", "Cate_Value"}),
#"Pivoted Column" = Table.Pivot(#"Removed Other Columns", List.Distinct(#"Removed Other Columns"[Category]), "Category", "Cate_Value")
in
#"Pivoted Column"

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.