Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Get Source Query Name for each Record of Merged Query

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.

3 REPLIES 3
collinsg
Super User
Super User

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.

Anonymous
Not applicable

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. 

vjingzhanmsft_0-1705891586824.png

 

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"

vjingzhanmsft_1-1705891788414.png

 

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!

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors