Forum Discussion
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 number | Data |
| 1 | A | 600000 | E |
| 3 | B | 700000 | D |
3 | C | 100000 | C |
4 | E | 200000 | G |
Desired result :
| Code | Category | Account number | Data |
| 1 | A | 600000 | E |
| 3 | B | 700000 | D |
3 | C | 100000 | C |
4 | E | 200000 | G |
| 1 | A | 600000 | E |
| 3 | B | 700000 | D |
Thank you for your help
- Anonymous3 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
- AnonymousNot 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
- bytesizetrainerNew Member
Works perfectly!!
- Power_BI_newFrequent 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 ]- ronrsnfldSuper User
Most likely you entered the code incorrectly, omitting the "{..}" around the List of tables
- KmcdonaldHelper III
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.
- Power_BI_newFrequent Visitor
Thank you very much for this detailed answer!