Forum Discussion
Copy and paste entire column value into another column based on current month or not
- 1 year ago
GokilaRaviraj , Try using below m-code
let
// Load your data source
Source = Excel.CurrentWorkbook(){[Name="YourTableName"]}[Content],// Add a column with the current month name
AddCurrentMonth = Table.AddColumn(Source, "CurrentMonth", each Date.ToText(DateTime.LocalNow(), "MMMM"), type text),// Duplicate the "Other income" column
DuplicateOtherIncome = Table.AddColumn(AddCurrentMonth, "CurrentMonthData", each [Other income]),// Add a conditional column to copy data based on the current month
AddConditionalColumn = Table.AddColumn(DuplicateOtherIncome, "UpdatedColumn", each if [CurrentMonth] = "September" then [CurrentMonthData] else null),// Remove unnecessary columns
RemoveColumns = Table.RemoveColumns(AddConditionalColumn,{"CurrentMonth", "CurrentMonthData"}),// Rename the updated column to the current month name
RenameColumn = Table.RenameColumns(RemoveColumns, {{"UpdatedColumn", Date.ToText(DateTime.LocalNow(), "MMMM")}})
in
RenameColumn
GokilaRaviraj , Try using below m-code
let
// Load your data source
Source = Excel.CurrentWorkbook(){[Name="YourTableName"]}[Content],
// Add a column with the current month name
AddCurrentMonth = Table.AddColumn(Source, "CurrentMonth", each Date.ToText(DateTime.LocalNow(), "MMMM"), type text),
// Duplicate the "Other income" column
DuplicateOtherIncome = Table.AddColumn(AddCurrentMonth, "CurrentMonthData", each [Other income]),
// Add a conditional column to copy data based on the current month
AddConditionalColumn = Table.AddColumn(DuplicateOtherIncome, "UpdatedColumn", each if [CurrentMonth] = "September" then [CurrentMonthData] else null),
// Remove unnecessary columns
RemoveColumns = Table.RemoveColumns(AddConditionalColumn,{"CurrentMonth", "CurrentMonthData"}),
// Rename the updated column to the current month name
RenameColumn = Table.RenameColumns(RemoveColumns, {{"UpdatedColumn", Date.ToText(DateTime.LocalNow(), "MMMM")}})
in
RenameColumn