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
Amardeep100115
Post Prodigy
Post Prodigy

How to remove unwanted columns dynamically

Hi 

 

I wish to remove unwanted columns from data by using "M-Code", not option "remove other colums in query editor.

 

Ref Link below

Link 

 

Thanks

Amardeep Bhingardeve
1 ACCEPTED SOLUTION

Hi @Amardeep100115 ,

 

Yes,for my .pbix file,pls click here.

 

Go to "edit queries">"Table">"steps",you will find my M-code there.

 

Best Regards,

Kelly

View solution in original post

8 REPLIES 8
v-kelly-msft
Community Support
Community Support

Hi @Amardeep100115

 

You can use M-code such as below:

 

= Table.RemoveColumns(Source,{"test"}&{"test 2"})

 

{"test"}{"test 2"} are the tables I removed,and you will see that in my previous table there are 3 columns:Date ,test, test 2,and with the M-code,there are only 1 column left.

 

51.png52.png

 

 
Best Regards,
Kelly

Thank you!

 

I tried the way you suggested, but not success got. could you please share your BI file to understand the same? if possible

 

Thanks occe again.

Amardeep Bhingardeve

Hi @Amardeep100115 ,

 

Yes,for my .pbix file,pls click here.

 

Go to "edit queries">"Table">"steps",you will find my M-code there.

 

Best Regards,

Kelly

not able to download 

Capture.PNG

Amardeep Bhingardeve

Hi @Amardeep100115

 

Try here.

 

Best Regards,
Kelly

JarroVGIT
Resident Rockstar
Resident Rockstar

You gave the video that answers your question?

 

Anyway, "Remove other columns" in Power query generates "M-code" for you (that is the whole point of the Query Editor, it generates the M code for you rather then having to create it yourself). You can also type in the M code yourself, I believe it is Table.SelectColumns() that returns a table with only the desired columns. 

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I am not much aware about M-code 

Please guide me on this more with any example

Please

Amardeep Bhingardeve

This question is too broad to answer. Why can't you use the "remove columns" option in power query editor? What have you tried already? Where exactly are you getting stuck?




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.

Top Solution Authors