Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi,
I have a source file with a dynamic number of columns, e.g.:
Year, Month, Budget revision 1, Budget revision 2, Budget revision 3...
I want to create a column called "Latest budget", that simply is a duplicate of the right most column in this table. I want to do this in the M query, and not in DAX or a measure.
I have found a function that will return the right most column name:
List.Last(Table.ColumnNames(#"Name of last step"))
However, using "Add column" with this function will simply print the column name, e.g. "Budget version 3". Instead, I want to get the values from that column. How can I acheive that?
Use the below step
=Table.DuplicateColumn(previous step, List.Last(Table.ColumnNames(previous step)),"Newcolumnname")
This worked!! Thanks.
@amitchandak See sample input and output below. The tricky part here is that the number of "Budget revision X" columns can vary, and the function needs to always duplicate the right-most column.
Sample input 1:
Year | Month | Budget revision 1 | Budget revision 2 |
2020 | 1 | 903920 | 1008930 |
2020 | 2 | 239450 | 345481 |
2020 | 3 | 802380 | 802389 |
2020 | 4 | 239509 | 299900 |
Sample output 1:
Year | Month | Budget revision 1 | Budget revision 2 | Last budget |
2020 | 1 | 903920 | 1008930 | 1008930 |
2020 | 2 | 239450 | 345481 | 345481 |
2020 | 3 | 802380 | 802389 | 802389 |
2020 | 4 | 239509 | 299900 | 299900 |
Sample input 2:
Year | Month | Budget revision 1 | Budget revision 2 | Budget revision 3 |
2020 | 1 | 903920 | 1008930 | 901512 |
2020 | 2 | 239450 | 345481 | 437457 |
2020 | 3 | 802380 | 802389 | 568852 |
2020 | 4 | 239509 | 299900 | 345634 |
Sample output 2:
Year | Month | Budget revision 1 | Budget revision 2 | Budget revision 3 | Last budget |
2020 | 1 | 903920 | 1008930 | 901512 | 901512 |
2020 | 2 | 239450 | 345481 | 437457 | 437457 |
2020 | 3 | 802380 | 802389 | 568852 | 568852 |
2020 | 4 | 239509 | 299900 | 345634 | 345634 |