Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi All,
When I add a custom table, it gets added at the end of the table.
Is there a way for us to define in M-Code, where we want the column to be inserted instead of end?
Solved! Go to Solution.
Yes, custom column is always added at the end and then you will have to reorder it. Below is a formula which combines these. Here I am inserting custom column at index position of 2.
= Table.ReorderColumns(Table.AddColumn(#"Changed Type", "Custom", each List.Sum(List.LastN(Record.ToList(_),3))),List.InsertRange(Table.ColumnNames(#"Changed Type"),2,{"Custom"}))
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Q", type text}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}, {"D", Int64.Type}, {"E", Int64.Type}, {"F", Int64.Type}, {"G", Int64.Type}}),
Result = Table.ReorderColumns(Table.AddColumn(#"Changed Type", "Custom", each List.Sum(List.LastN(Record.ToList(_),3))),List.InsertRange(Table.ColumnNames(#"Changed Type"),2,{"Custom"}))
in
Result
Hi @GulianiG
You can use Transform > Move to move the custom column to another position after creating it. This would be easier. https://docs.microsoft.com/power-query/move-columns
After you move a column, you will see the code of this step. The columns display in the order of the column name list. You can also change the item order in the list to change their display order.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Yes, custom column is always added at the end and then you will have to reorder it. Below is a formula which combines these. Here I am inserting custom column at index position of 2.
= Table.ReorderColumns(Table.AddColumn(#"Changed Type", "Custom", each List.Sum(List.LastN(Record.ToList(_),3))),List.InsertRange(Table.ColumnNames(#"Changed Type"),2,{"Custom"}))
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Q", type text}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}, {"D", Int64.Type}, {"E", Int64.Type}, {"F", Int64.Type}, {"G", Int64.Type}}),
Result = Table.ReorderColumns(Table.AddColumn(#"Changed Type", "Custom", each List.Sum(List.LastN(Record.ToList(_),3))),List.InsertRange(Table.ColumnNames(#"Changed Type"),2,{"Custom"}))
in
Result
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
16 | |
10 | |
10 | |
8 | |
7 |