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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
PaoloB
New Member

Passing a list of column names as a variable

I'm fairly new with M and am trying to pass a list of column names as a variable to eventually allow query authors to specify columns to select for other queries. In my table "Projects," I have 9 columns. In my list "TestList," I specify four column names. One of those names (Peach) doesn't exist in "Projects." I then get the intersection of the Project column names list and TestList to give me the list of columns I actually want.

 

What I'd like to do next is retrieve Projects table data from the resulting list of columns. I've done some searching, but haven't found anything to answer my question--or anything I can understand anyway. I don't know if it's just a syntax thing or fundamental conceptual ignorance, so I'd appreciate any help. Here's the simple query:

 

let
  TestList = {"ProjectId", "ProjectName", "RelativeURL","Peach"},
  TabCols = Table.ColumnNames(Projects),
  IntersectCols = List.Intersect({TestList, TabCols}),
  RetrieveCols = Projects[IntersectCols]
in
  RetrieveCols

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

RetrieveCols = Table.SelectColumns(Projects,IntersectCols)

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

RetrieveCols = Table.SelectColumns(Projects,IntersectCols)

Perfect. Thank you so much!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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