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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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
Top Kudoed Authors