Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
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 |