Forum Discussion
Trying to create a new column based on the query or source file name.
- 6 years ago
Hi dmarics28 ,
Try to change the code of your Append query in the Advanced Editor.
let Source = Table.Combine({Table.AddColumn(#"query A", "source query", each "query A") , Table.AddColumn(#"query B", "source query", each "query B") , Table.AddColumn(#"query C", "source query", each "query C")}) in SourceBTW, .pbix file attached.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi dmarics28 ,
1) In Power Query, go to New Source>Blank Query>Advanced Editor and paste this code over the default code:
let
Source = #sections,
Section1 = Source[Section1],
convertTable = Record.ToTable(Section1)
in
convertTableThis will load a table with all components of your Power Query setup.
2) Filter the [Name] column to include only the names of the tables that you want to append. Once you have done this, you will see that the dropdown button in the column header changes to an expand button:
3) Expand this as you would after a Merge/Join including all columns that are the same in both queries:
4) You will then have an appended table which includes the source query name in each:
Pete
- BA_Pete6 years agoSuper User
Yes, unfortunately #sections and #shared are Power Query environment only. I should have checked your use-case first.
In terms of carrying the appended query names over, on balance of time/effort, I see your options as follows:
1) Manually add a column into each of your PRE-APPENDED tables, like ="myTableName1", ="myTableName2" etc. Ensure these columns have the same field name and data type in each table and the append process will bring them in correctly the same as all the other data columns.
2) Use your data source to create a 'Source Name' table that is bundled with the main data table. For example, in Excel you could create another tab that just contains the name that you want the source to be called. Bring this table in with the main data and then use it as a source to reference in an added column in Power Query. In reality, this essentially achieves the same as option 1), but in a far more roundabout way.
Pete