How to Get Table Name in Power BI
Trying to show which table a visual is currently using can be surprisingly tricky in Power BI. You might want a chart title to dynamically update or simply need a reference to clarify the data source for your users. This quick guide will walk you through a couple of tried-and-true methods for getting a table name to display in your Power BI reports using DAX and Power Query.
Why Would You Need a Table’s Name?
Before diving into the "how," let's quickly cover the "why." Pinpointing the source table isn't just a technical exercise, it solves real-world reporting challenges. Here are a few common scenarios where this feature comes in handy:
- Dynamic Chart Titles: Instead of text like "Sales Over Time," you could have a title that reads "Sales Over Time (from Sales_2023 Data)." When a user selects a different year from a slicer, the title updates automatically.
- Improved Report Clarity: In complex reports with data blended from multiple similar tables (like monthly sales exports), displaying the source table name gives end-users confidence in what they're looking at.
- Easier Debugging: When building and testing complex measures, being able to confirm which table the calculation is hitting can save a lot of time and frustration.
- Model Documentation: You can create special pages within your report that list tables and their contexts, helping other developers understand the model.
The Best Practice: Add a Source Column in Power Query
Let's start with the most robust and recommended method. Instead of relying purely on complex DAX, the cleanest way to track a table's origin is by adding a source column before a table even gets to your DAX measures. This is done in the Power Query Editor.
This approach is perfect for the common scenario where you have multiple tables with the same structure that you want to combine, such as monthly or yearly sales data (e.g., Sales_2022, Sales_2023, Sales_2024).
Step-by-Step Instructions
Here’s how to set this up using the Power Query append method:
1. Open the Power Query Editor: In Power BI Desktop, navigate to the Home tab and click on Transform data.
2. Add a Custom Column to Each Table:
- Select your first table (for this example, let's call it
Sales_2022). - Go to the Add Column tab in the ribbon and click Custom Column.
- In the popup window, name the new column something intuitive, like "Source Table" or "Data Year."
- In the formula box, hardcode the table's name in quotes, like this:
"Sales_2022". - Click OK. You will now see a new column where every row has the value "Sales_2022."
Repeat this exact process for your other tables (e.g., Sales_2023, Sales_2024), changing the hardcoded text in the formula to match the table name each time.
3. Append the Tables Together:
- Now that each table is tagged, you can safely merge them without losing track of where each row came from.
- On the Home tab in Power Query, click the dropdown for Append Queries and select Append Queries as New.
- In the Append window, select "Three or more tables" if needed. Then, add all the tables you prepared into the "Tables to append" list.
- Click OK. Power Query will generate a new table (by default named 'Append1') containing all the data from your source tables, including the new 'Source Table' column you created.
4. Load to Model:
- Rename the newly appended table to something meaningful, like "All Sales."
- Click Close & Apply in the top-left corner to load your work into the Power BI data model. It's also a good practice at this stage to right-click on the original individual source tables and uncheck Enable load to prevent them from being loaded into the model, which saves on memory and reduces clutter.
Using Your New 'Source Table' Column
Now that the hard work is done in Power Query, using the table name is incredibly simple.
- Slicers and Filters: You can drag the
'All Sales'[Source Table]column directly onto your report canvas to create a slicer or use it in the Filters pane. - Dynamic Titles: You can create a simple measure to display the selected source.
Selected Source = "Data From: " & SELECTEDVALUE('All Sales'[Source Table], "All Sources")Then, navigate to the formatting options for any visual, go to General > Title, and click the fx (Conditional formatting) button. In the dialog box, select your new measure, [Selected Source], as the field to drive the title. Now, whenever a user clicks a value in the slicer, your chart's title will update instantly!
Method 2: Using a Disconnected Table and DAX
What if your tables are not meant to be appended? Maybe they contain very different types of data, but you want to use a slicer to show data from one or the other. In this case, you can use a "disconnected table" to act as a controller for your measures.
A disconnected table doesn't have a relationship with any other tables in your model. It purely exists to hold values for slicers, which you can then capture with DAX to control report logic.
Step-by-Step Instructions
1. Create a Control Table:
- On the Home tab in Power BI Desktop, click Enter Data.
- Create a single-column table. Name the column something like "Selector." In the rows, enter the names of the tables you want your users to be able to choose from. For example, "Products" and "Customers."
- Name this new table "Table Selector" and click Load.
2. Build Your Report Visuals:
- Create a slicer on your report page using the
'Table Selector'[Selector]column. - Imagine you need a single visual (like a Card) that can show either the count of products or the count of customers. To do this, you’ll write a "switcher" measure.
3. Write a DAX "Switcher" Measure:
This measure will first find out what the user selected in the slicer and then perform a different calculation based on that selection.
Dynamic Count Measure =
VAR SelectedTable = SELECTEDVALUE('Table Selector'[Selector])
RETURN
SWITCH(
TRUE(),
SelectedTable = "Products", COUNTROWS(Products),
SelectedTable = "Customers", COUNTROWS(Customers),
BLANK() // Return blank if nothing or multiple values are selected
)4. Get the Table Name: Getting the name of the selected table is even easier. You just need the first part of the measure above.
Selected Table Name = SELECTEDVALUE('Table Selector'[Selector], "Nothing Selected")You can drop this [Selected Table Name] measure into a card visual or use it as a dynamic title just like in the previous method. When a user selects "Products" from the slicer, the card will display "Products," and the [Dynamic Count Measure] will show the product count. If they select "Customers," it will update to show the customer count.
The key takeaway is that you are not dynamically detecting a table name from context, rather, you are providing the user a menu of table names and using their selection to control which code path your DAX measure executes.
Advanced Method: Querying DMVs with DAX Studio
For those who need to extract a comprehensive list of all tables within their model for documentation or analysis, neither of the above methods is efficient. Instead, you can use external tools like DAX Studio to query the Dynamic Management Views (DMVs) that underpin your Power BI model.
DMVs are special views that return information about the data model’s objects, server state, and queries. You can't use them in a standard visual inside Power BI, but they are incredibly useful for developers.
How to Get a List of All Tables:
- Install and open DAX Studio.
- Connect DAX Studio to your open Power BI Desktop file (.pbix).
- In the query pane, type the following query:
SELECT * FROM $SYSTEM.TMSCHEMA_TABLES- Click Run.
DAX Studio will return a fully queryable results grid containing the names of all tables in your model (both visible and hidden), their descriptions, partitions, and other metadata. You can easily copy and paste this information into Excel or another documentation tool.
Final Thoughts
Dynamically displaying a table's name is a common need for making Power BI reports more user-friendly and easier to manage. For most day-to-day scenarios, tagging and combining your tables in Power Query is the cleanest, most efficient method because it builds good data modeling habits and keeps your DAX simple.
This illustrates how a lot of work in a tool like Power BI goes into preparing and modeling the data before you can even build visuals. This upfront effort - creating schema, writing custom logic, and authoring DAX - is essential. As a result, we created Graphed to simplify this workflow entirely. You just connect your data sources with a few clicks, and instead of wrestling with menus and code, simply ask your question in plain English. Graphed handles the data modeling and visualization behind the scenes, turning hours of report-building tasks into a quick, conversational experience.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.