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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
magnus_b
Advocate II
Advocate II

Duplicate last column

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?

4 REPLIES 4
Nikshiptha
Frequent Visitor

Use the below step

=Table.DuplicateColumn(previous step, List.Last(Table.ColumnNames(previous step)),"Newcolumnname")

Nikshiptha
Frequent Visitor

This worked!! Thanks.

amitchandak
Super User
Super User

@magnus_b ,Can you share sample data and sample output in table format?

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@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:

YearMonthBudget revision 1Budget revision 2
202019039201008930
20202239450345481
20203802380802389
20204239509299900


Sample output 1:

YearMonthBudget revision 1Budget revision 2Last budget
2020190392010089301008930
20202239450345481345481
20203802380802389802389
20204239509299900299900

 



Sample input 2:

YearMonthBudget revision 1Budget revision 2Budget revision 3
202019039201008930901512
20202239450345481437457
20203802380802389568852
20204239509299900345634

 


Sample output 2:

YearMonthBudget revision 1Budget revision 2Budget revision 3Last budget
202019039201008930901512901512
20202239450345481437457437457
20203802380802389568852568852
20204239509299900345634345634

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors