Forum Discussion

Power_BI_new's avatar
Power_BI_new
Frequent Visitor
3 years ago
Solved

Duplicate rows in Power Query

Good morning 🙂,

I have a database with steps applied to it on Power Query, I would like to add one last step to:
duplicate all the rows of my table whose "Account number" column begins with 6 or 7. I'll give you an example of what I want with a before and after:

 

Code Category Account numberData 
1600000E
3B700000D

3

C100000C

4

E200000G


Desired result : 

Code Category Account numberData 
1600000E
3B700000D

3

C100000C

4

E200000G
1600000E
3B700000D


Thank you for your help

  • Anonymous's avatar
    Anonymous
    3 years ago

    Say you are at step name FullTable. Just filter to include only the accounts you want to duplicate, name this step Filtered, and then

     

    = Table.Combine({FullTable, Filtered})

     

    You can refer to any step in any order.

     

    --Nate

  • Hi Power_BI_new,

    I put together your example provided to show you how I achieved this differently than the other suggestions.

     

    So once I put together the data in an xlsx file, I started with the sample below. Please note that I had formatted the "Account Number" column as text.

     

     

    So the first step was that I clicked the "Add Step" button to create a starting point and named the new step, "--original_data".

     

     

    Then I used a filter on the "Account Number" column, using the text filter begins with a 6 or 7.

     

    Then I appended the current query onto itself.

     

     

    Then as the last step, when you select the append query step it will show the name of the query twice. So I changed one of those names to the "--original_data" step name, that I name in the first step.

     

    from:

     

    to:

     

    This is my final result, which I believe matches what you are trying to acheive.

     

     

    If I'm not coming accross clearly, happy to share the pbix file I put together if you have somewhere I can drop it 🙂

    If you need to, you can change the account number back to a whole number format.

     

     

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Say you are at step name FullTable. Just filter to include only the accounts you want to duplicate, name this step Filtered, and then

     

    = Table.Combine({FullTable, Filtered})

     

    You can refer to any step in any order.

     

    --Nate

    • Power_BI_new's avatar
      Power_BI_new
      Frequent Visitor

      Thank you for your answer, but it gives me this error:

       

      Sorry... We couldn't convert a value of type Table to type List:

      Details :
      Value = [ Table ]
      Type = [ Type ]

      • ronrsnfld's avatar
        ronrsnfld
        Super User

        Most likely you entered the code incorrectly, omitting the "{..}" around the List of tables

  • Hi Power_BI_new,

    I put together your example provided to show you how I achieved this differently than the other suggestions.

     

    So once I put together the data in an xlsx file, I started with the sample below. Please note that I had formatted the "Account Number" column as text.

     

     

    So the first step was that I clicked the "Add Step" button to create a starting point and named the new step, "--original_data".

     

     

    Then I used a filter on the "Account Number" column, using the text filter begins with a 6 or 7.

     

    Then I appended the current query onto itself.

     

     

    Then as the last step, when you select the append query step it will show the name of the query twice. So I changed one of those names to the "--original_data" step name, that I name in the first step.

     

    from:

     

    to:

     

    This is my final result, which I believe matches what you are trying to acheive.

     

     

    If I'm not coming accross clearly, happy to share the pbix file I put together if you have somewhere I can drop it 🙂

    If you need to, you can change the account number back to a whole number format.