Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
Hi Guys,
I am trying to create a simple new column in my dataset. But I need the data to be the Query name.
What is the formula for Query Name? Or Source File name? Thanks in advance.
Solved! Go to Solution.
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
Source
BTW, .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 ,
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
Source
BTW, .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.
@Icey
Thanks that did work.
However, i have about 20 or 30 data sources, and typing each one is very time consuming.
And need to edit the code each time i need to add another source.
If somehow there was a formula instead on manually typing source name in the advanced editor, that would help.
But thanks to everyone who put some ideas forward on this.
// out
let
Source = Record.ToTable(Record.RemoveFields(#sections[Section1],"out")),
expd = Table.ExpandTableColumn(Source, "Value", {"Value"}, {"Value.1"})
in
expd
// first
let
Source = Table.FromValue({1..5})
in
Source
// second
let
Source = Table.FromValue({1..5})
in
Source
Here are three queries combined for a demonstration to see if this is what you want, That's as far as I can go
the query ribbon → Add Column → Custom Column →
Text.Combine(Record.FieldNames(Record.RemoveFields(#sections[Section1], "Append1")),", ")
Append1 is the name of the current query, Since Sections also display the name of the current query, the name of the current query should be removed
@ziying35
No, this is no good either. This is just giving me all the query names concatenated together seperated by "," All in the same cell.
I need the new column to have the name of the query where the appended data originated from.
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
convertTable
This 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
Proud to be a Datanaut!
For me, this does perfectly the job. Thank you
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
Proud to be a Datanaut!
Do you want to get a list of all query names for the current file in a new column? Or a list collection that references all queries?
@ziying35
I want to create a new column in my appended query.
The new column cells need to reference just the query name that the original data came from.
Can this be done?
= Table.AddColumn(PreviousStep, "query names", (r)=>Record.FieldNames(Record.RemoveFields(#sections[Section1], "Append1")))
Append1 is the name of the current query, Does it help you to look at this
@ziying35
Nope. No good.
Expression.Error: The name 'PreviousStep' wasn't recognized. Make sure it's spelled correctly.
Replace PreviousStep with the name of the previous step in your query, such as Source
You can just put = Query1 (the name of your query). This will add the entire query into a table on each row. Is that your desired outcome?
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
No, That didnt work.
That returned an error.
Expression.Error: The name 'query1' wasn't recognized. Make sure it's spelled correctly.
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
User | Count |
---|---|
23 | |
10 | |
10 | |
9 | |
9 |