Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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

  • Hi Anonymous ,

     

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

     

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

     

    Best Regards,

    Kelly

8 Replies

  • JarroVGIT's avatar
    JarroVGIT
    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! 🙂

    • Anonymous's avatar
      Anonymous
      Not applicable

      I am not much aware about M-code 

      Please guide me on this more with any example

      Please

      • JarroVGIT's avatar
        JarroVGIT
        Resident Rockstar
        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?
  • v-kelly-msft's avatar
    v-kelly-msft
    Community Support

    Hi Anonymous ,

     

    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.

     

     

     
    Best Regards,
    Kelly

    • Anonymous's avatar
      Anonymous
      Not applicable

      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.

      • v-kelly-msft's avatar
        v-kelly-msft
        Community Support

        Hi Anonymous ,

         

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

         

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

         

        Best Regards,

        Kelly