Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
After merging multiple queries, how do I make a custom column that shows which query each record is sourced from?
Example:
I am new to Power Query and I have no clue how to achieve this.
Good day kbl_22
Before appending the queries you could add a column to Table 1, call it "Source" and give it the value "Table 1". Do the same for Table 2. Then append the queries (it looks from the example you have an append rather than a merge).
Hope this helps
Hi @Syndicate_Admin ,
Apologies for the confusion, the example I gave is just a visualization of what I want to achieve because I need it to be dynamic. My merged table consists of multiple left outer merges and I need to label each record which query matches the record in a Source column.
Hi kbl_22
Currently Power Query doesn't have a direct funtion to fill a column with its query name. You may vote this idea: A PowerQuery (M) function that returns the name of currently executing query
As you will left outer merge multiple queries, you will find that if there is any match record, the merged table value has rows. And the merged table value is empty when there is no match.
Based on above, you can add a custom column to have the table name based on the merged table value's row count. You need to perform this step manually after every merging.
if Table.RowCount([Table2]) > 0 then "Table2" else "Table1"
If this doesn't help, you may consider using the environment keywords #shared or #sections. But this may not be used easily and cannot work in the Power BI Service. You may refer to below links to read more:
Get List of Queries in Power BI
Dynamic source table name in Power Query - Microsoft Fabric Community
Refer to current Query Name in formula - Microsoft Fabric Community
excel - Power Query: return self (this) query name - Stack Overflow
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 8 | |
| 7 |