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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
charl_cfm
New Member

Alphabetic M-Code list

Below is the M-Code in Power Query for removing columns (this is from a model that I am using). Is it possible to arrange the list alphabetically for ease of future reference?

 

Table.RemoveColumns(dbo_tblPODetail,{"StockItem_ID","VatRateID", "VatRatePerc", "VatValue", "PriceIncl", "TotalVAT", "TotalIncl", "Category_ID", "Category_Code", "Category", "Subcategory_ID", "Subcategory_Code", "Subcategory1_ID", "Subcategory1_Code", "Variety_ID", "Variety_Code", "Packing_ID", "Packing_Code", "Size_ID", "Size_Code", "Grade_ID", "Grade_Code", "ProdAllocationID", "ProdAllocationCode","PriceExclDiscounted", "UOM_ID", "Supplier_Group_ID", "Supplier_Group_Code", "Supplier_Group", "Supplier_Group_Price_ID", "Supplier_Group_Price_Period_Start", "Supplier_Group_Price_Period_End", "Price_Per_Outer_Pack", "TotalCalculation", "Costing_Type", "Price_Per_kg","Subcategory", "Subcategory1", "Variety", "Packing", "Size", "Grade", "PackSize","Std_Wgt_Per_Outer_Pack", "Price_Week","Origin_Doc_Line_ID"})

1 ACCEPTED SOLUTION
spinfuzer
Solution Sage
Solution Sage

I am not sure if there is a slicker way, but you can create a blank query and use List.Sort and Text.Combine like below

 

 

let
    Source = Text.Combine(
        List.Sort(
            {"StockItem_ID","VatRateID", "VatRatePerc", "VatValue", "PriceIncl", "TotalVAT", "TotalIncl", "Category_ID", "Category_Code", "Category", "Subcategory_ID", "Subcategory_Code", "Subcategory1_ID", "Subcategory1_Code", "Variety_ID", "Variety_Code", "Packing_ID", "Packing_Code", "Size_ID", "Size_Code", "Grade_ID", "Grade_Code", "ProdAllocationID", "ProdAllocationCode","PriceExclDiscounted", "UOM_ID", "Supplier_Group_ID", "Supplier_Group_Code", "Supplier_Group", "Supplier_Group_Price_ID", "Supplier_Group_Price_Period_Start", "Supplier_Group_Price_Period_End", "Price_Per_Outer_Pack", "TotalCalculation", "Costing_Type", "Price_Per_kg","Subcategory", "Subcategory1", "Variety", "Packing", "Size", "Grade", "PackSize","Std_Wgt_Per_Outer_Pack", "Price_Week","Origin_Doc_Line_ID"}
        ), 
        ", "
    )
in
    Source

 

 

Then copy and paste the output into your query.

View solution in original post

4 REPLIES 4
spinfuzer
Solution Sage
Solution Sage

I am not sure if there is a slicker way, but you can create a blank query and use List.Sort and Text.Combine like below

 

 

let
    Source = Text.Combine(
        List.Sort(
            {"StockItem_ID","VatRateID", "VatRatePerc", "VatValue", "PriceIncl", "TotalVAT", "TotalIncl", "Category_ID", "Category_Code", "Category", "Subcategory_ID", "Subcategory_Code", "Subcategory1_ID", "Subcategory1_Code", "Variety_ID", "Variety_Code", "Packing_ID", "Packing_Code", "Size_ID", "Size_Code", "Grade_ID", "Grade_Code", "ProdAllocationID", "ProdAllocationCode","PriceExclDiscounted", "UOM_ID", "Supplier_Group_ID", "Supplier_Group_Code", "Supplier_Group", "Supplier_Group_Price_ID", "Supplier_Group_Price_Period_Start", "Supplier_Group_Price_Period_End", "Price_Per_Outer_Pack", "TotalCalculation", "Costing_Type", "Price_Per_kg","Subcategory", "Subcategory1", "Variety", "Packing", "Size", "Grade", "PackSize","Std_Wgt_Per_Outer_Pack", "Price_Week","Origin_Doc_Line_ID"}
        ), 
        ", "
    )
in
    Source

 

 

Then copy and paste the output into your query.

Thank you!

charl_cfm
New Member

Hi Greg, thanks. Not sure if I missed it, but how do you do the alphabetic sorting?

Greg_Deckler
Community Champion
Community Champion

@charl_cfm Here you go:

"Category","Category_Code","Category_ID","Costing_Type","Grade","Grade_Code","Grade_ID","PackSize","Packing","Packing_Code","Packing_ID","PriceIncl","Price_Per_Outer_Pack","Price_Per_kg","Price_Week","ProdAllocationCode","ProdAllocationID","Size","Size_Code","Size_ID","Subcategory1","Subcategory1_Code","Subcategory1_ID","Subcategory_Code","Subcategory_ID","Supplier_Group","Supplier_Group_Code","Supplier_Group_ID","Supplier_Group_Price_ID","Supplier_Group_Price_Period_End","Supplier_Group_Price_Period_Start","TotalCalculation","TotalIncl","TotalVAT","UOM_ID","Variety","Variety_Code","Variety_ID","VatRatePerc","VatValue","Origin_Doc_Line_ID","PriceExclDiscounted","Std_Wgt_Per_Outer_Pack","StockItem_ID","Subcategory","VatRateID"



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.