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

Create Duplicate Entries based on Column Value and change data entries

I want to add a duplicate of a row in my existing table based on value in another column in the same table using power query:

 

I have a column called 'ITM CODE' in my table.  I want, for every row where the ITM CODE = SLMANFEE, that entire row to be duplicated and placed at the bottom of the existing table.  Then I want the data the the second column of the copied row to be changed to "WMC".

 

Any help would be appreciated.

 

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @DeanP

In Power Query

Assume your table is "Sheet9"

create a new blank query, open Advanced editor, write the code

let
   Source= Table.SelectRows(Sheet9, each[ITM CODE]="SLMANFEE")
in
   Source

2.png

then in this table, 

click on the [ITM CODE] column, select "Transform"->Replace values,

3.png

 

Then in Sheet9, select "Home"->Append Queries", Append Queries as new, 

4.png

 

Please refer to my pbix.

 

Best Regards

Maggie

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @DeanP

You could also use the following code in your data table to create Duplicate Entries directly.

let
    Source = Excel.Workbook(File.Contents("C:\Users\maggiel\Desktop\case\11\11.28\11.28.xlsx"), null, true),
    Sheet9_Sheet = Source{[Item="Sheet9",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet9_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"col1", Int64.Type}, {"ITM CODE", type text}, {"col3", Int64.Type}, {"col4", type text}, {"col5", type text}}),
    Source2 = Table.SelectRows(#"Changed Type", each[ITM CODE]="SLMANFEE"),
    #"Replaced Value" = Table.ReplaceValue(Source2,"SLMANFEE","WMC",Replacer.ReplaceText,{"ITM CODE"}),
    final=Table.Combine({#"Changed Type", #"Replaced Value"})
in
    final

Best Regards

Maggie

v-juanli-msft
Community Support
Community Support

Hi @DeanP

In Power Query

Assume your table is "Sheet9"

create a new blank query, open Advanced editor, write the code

let
   Source= Table.SelectRows(Sheet9, each[ITM CODE]="SLMANFEE")
in
   Source

2.png

then in this table, 

click on the [ITM CODE] column, select "Transform"->Replace values,

3.png

 

Then in Sheet9, select "Home"->Append Queries", Append Queries as new, 

4.png

 

Please refer to my pbix.

 

Best Regards

Maggie

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.