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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
gvg
Post Prodigy
Post Prodigy

Getting a list of all columns in all tables in the data model

Hi folks,

 

I am looking to get all the names of the columns of all the tables in a data model. No data, just the column names in a simple table like this:

Table       ColumnName
------- ---------- Table1      id Table1      CustCode Table1      Amount Table2    id .....       .....

I created a list of all the tables TableList but not sure how to iterate that list when column names are unknown?

 

Thanks for your hints.

 

 

 

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

you could use #shared for this, but then you have to manually filter the queries

let
    Source = #shared,
    #"Converted to Table" = Record.ToTable(Source),
    #"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Name] = "Query")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Column", each Table.ColumnNames([Value])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value"}),
    #"Expanded Column" = Table.ExpandListColumn(#"Removed Columns", "Column")
in
    #"Expanded Column"


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

15 REPLIES 15
zita_helle
New Member

A much easier way with types and all:

 

let

   schema_table = Table.Schema(airbnb)
in
   schema_table

Stachu
Community Champion
Community Champion

you could use #shared for this, but then you have to manually filter the queries

let
    Source = #shared,
    #"Converted to Table" = Record.ToTable(Source),
    #"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Name] = "Query")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Column", each Table.ColumnNames([Value])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value"}),
    #"Expanded Column" = Table.ExpandListColumn(#"Removed Columns", "Column")
in
    #"Expanded Column"


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

@Stachu , this doesn't work for me. There are no values "Query" in the [Name] column.

Stachu
Community Champion
Community Champion

"Query" was a name of a table that was in my model, you need to filter for whatever are your query names


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

OK, thank you @Stachu !

OK, never seen this #shared before. Can you explain a little how this script works?

Nolock
Resident Rockstar
Resident Rockstar

Hi @gvg,

#shared is a record, which contains all tables (queries) and functions. It is a mixture of the PBI core functionality and your custom objects. Check the screenshot below.

Please be carefull with #shared. It isn't supported for refreshes in Power BI Service. It works only in Power BI Desktop. More about the problem: https://community.powerbi.com/t5/Power-Query/Expression-Evaluate-shared-in-PowerBI-Service/td-p/7316...

And to an untold question, which would come as next for sure: Unfortunately, there isn't another way how to get all columns of all tables.

 

Capture.PNG

Anonymous
Not applicable

Hi @Nolock  and @Stachu 

 

I'm using the #shared object to get a list of tables and columns in my model. I wanted a dynamic list of columns and tables for a governance workflow. But I've found that it only instatiates these values within the query editor. When the query is applied and the table viewed in the report editor the values of any tables in the query editor are not populated.

 

Sure I can copy and paste the values..... but this is not the dynamic approach I require.

 

I'm wondering if anyone has any ideas how to persist the values in a way that survives the query being applied to the model ?

 

For example using the code below

 

let
Source = #shared,
#"Converted to Table" = Record.ToTable(Source),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Column", each try Table.ColumnNames([Value]) otherwise null),
#"Expanded Column" = Table.ExpandListColumn(#"Added Custom", "Column"),
#"Filtered Rows" = Table.SelectRows(#"Expanded Column", each ([Column] <> null)),
#"Removed Duplicates" = Table.Distinct(#"Filtered Rows", {"Name"}),
#"Removed Columns" = Table.RemoveColumns(#"Removed Duplicates",{"Value", "Column"})
in
#"Removed Columns"

 

I've been trying to persist the values instantiated in query editor to another table in some way. e.g. custom column, convert to list, merge with another table..... but so far all these refresh to null values 😞

 

Hoping someone has a clever way.

 

Anonymous
Not applicable

Try this one:

let
Source = #shared,
#"Converted to Table" = Record.ToTable(Source),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Column", each try Table.ColumnNames([Value]) otherwise null),
#"Expanded Column" = Table.ExpandListColumn(#"Added Custom", "Column"),
#"Filtered Rows" = Table.SelectRows(#"Expanded Column", each ([Column] <> null)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"})
in
#"Removed Columns"

Where do I put this code? I'd like to create a new table showing all the tables and columns associated with this .pbix file. Any leads? 

Thank you.

I was able to figure it out:

- Click "Add data" to create a new table

- Enter "test" into one column

- Click "Transform data"

- Paste the code from @Anonymous into the "Advanced Editor"

How do we get the view to persist?

In the query editor for the new table, all TableNames and ColumnNames are shown...

image.png

But as soon as I `Close and Apply`, none of the values are visible...?

image.png

Anonymous
Not applicable

I also have a similar requirement, any got how to make these values persistent?

Did you figure this out? Getting same thing

Hello friend! Didi you solved this problem? Chears

Thank you @Nolock !

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.