- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

How to delete the last column of data without referencing column names?
I have data that includes a total column at the end that summed across the rows. I want to delete this column, but I can't click on it and delete it as the column name may change when the data source is updated, causing errors. So I am looking for a function of some type that deletes the last column and won't cause any errors if all the column names in the source are changed.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VVFLEoUwCLuLaxcC/dizON7/Go+kTZ23MKMCCQnPc5RxnIdFgjdAPqUkBMA63vBcCTf+3KvJSzve85kD/LnBWDdAFbnxk1R1f9ZOCqqwFZqFjEPqFDQWMFOxCBYteIlkJAOaunhZIh/XdsBY+3O+yp82QDW+IEz10KhBMmy7qYvF0w0I6J1hoVyafLjLhw+1cJ+4t1CKMEgOMYXQEXZoE7pmbPwVIv0zhqqsoq9AuHO4DA3pk2FGTWvXvGYoHp606aJzIypfsv+dg5tH9rzvDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"20201218" = _t, #"20201221" = _t, #"20201222" = _t, #"20201223" = _t, #"20210104" = _t, #"20210105" = _t, #"20210106" = _t, #"20210107" = _t, #"20210108" = _t, #"20210110" = _t, #"20210111" = _t, #"20210112" = _t, #"20210113" = _t])
in
Source

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VVFLEoUwCLuLaxcC/dizON7/Go+kTZ23MKMCCQnPc5RxnIdFgjdAPqUkBMA63vBcCTf+3KvJSzve85kD/LnBWDdAFbnxk1R1f9ZOCqqwFZqFjEPqFDQWMFOxCBYteIlkJAOaunhZIh/XdsBY+3O+yp82QDW+IEz10KhBMmy7qYvF0w0I6J1hoVyafLjLhw+1cJ+4t1CKMEgOMYXQEXZoE7pmbPwVIv0zhqqsoq9AuHO4DA3pk2FGTWvXvGYoHp606aJzIypfsv+dg5tH9rzvDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"20201218" = _t, #"20201221" = _t, #"20201222" = _t, #"20201223" = _t, #"20210104" = _t, #"20210105" = _t, #"20210106" = _t, #"20210107" = _t, #"20210108" = _t, #"20210110" = _t, #"20210111" = _t, #"20210112" = _t, #"20210113" = _t]),
#"New" = let max = Table.ColumnCount(Source) in Table.RemoveColumns(Source, {Table.ColumnNames(Source){max - 1}})
in
#"New"
--Nate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thank you for this. I'm still learning M and am a little confused with the 'let' here. Are you able to explain a little about how it works and why it is used here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I may have solved it, but if anyone has a better way please let me know. I would like to know how to hide the variable name 'max' from the Applied Steps list.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VVFLEoUwCLuLaxcC/dizON7/Go+kTZ23MKMCCQnPc5RxnIdFgjdAPqUkBMA63vBcCTf+3KvJSzve85kD/LnBWDdAFbnxk1R1f9ZOCqqwFZqFjEPqFDQWMFOxCBYteIlkJAOaunhZIh/XdsBY+3O+yp82QDW+IEz10KhBMmy7qYvF0w0I6J1hoVyafLjLhw+1cJ+4t1CKMEgOMYXQEXZoE7pmbPwVIv0zhqqsoq9AuHO4DA3pk2FGTWvXvGYoHp606aJzIypfsv+dg5tH9rzvDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"20201218" = _t, #"20201221" = _t, #"20201222" = _t, #"20201223" = _t, #"20210104" = _t, #"20210105" = _t, #"20210106" = _t, #"20210107" = _t, #"20210108" = _t, #"20210110" = _t, #"20210111" = _t, #"20210112" = _t, #"20210113" = _t]),
max = Table.ColumnCount(Source),
#"New" = Table.RemoveColumns(Source, {Table.ColumnNames(Source){max - 1}})
in
#"New"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would use:
= Table.RemoveColumns( PreviousStep, List.Last( Table.ColumnNames( PreviousStep ) ) )
or to make it more generic:
= Table.RemoveColumns( PreviousStep, List.LastN( Table.ColumnNames( PreviousStep ), 1 ) )

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.
Join our Community Sticker Challenge 2025
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Subject | Author | Posted | |
---|---|---|---|
07-17-2024 03:26 AM | |||
06-30-2024 07:54 PM | |||
05-23-2024 04:19 PM | |||
03-12-2024 07:59 AM | |||
03-15-2024 07:36 AM |