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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
GokilaRaviraj
Helper II
Helper II

Copy and paste entire column value into another column based on current month or not

Hi 

 

Can anyone please tell me how to copy entire column data and paste that values in another empty column based on current month name.

GokilaRaviraj_0-1725443417604.png

This is how my table looks now. Since we are in September month, Other income value has to be copied in September and other column values i need to enter manual data. 

I have fetched current month + 11 months dynamically and appended those to this table where in im trying to copy and paste.

 

Please give me some solution.

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@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




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

3 REPLIES 3
dufoq3
Super User
Super User

Hi @GokilaRaviraj, check this:

 

Result

dufoq3_0-1725453915851.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTI0ABJQFKsTrZQEZBihiSUDGcbIYrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Company Name" = _t, #"Other Income" = _t, september = _t, october = _t, november = _t]),
    // You can probably delete this step with your data.
    ReplaceBlankToNull = Table.TransformColumns(Source, {}, each if _ = "" then null else _),
    ChangedType = Table.TransformColumnTypes(ReplaceBlankToNull,{{"Other Income", type number}}),
    ReplacedCurrentMonth = Table.ReplaceValue(ChangedType,
        each null,
        each [Other Income],
        Replacer.ReplaceValue,
        {Text.Lower(DateTime.ToText(DateTime.FixedLocalNow(), "MMMM", "en-US"))} )
in
    ReplacedCurrentMonth

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

bhanu_gautam
Super User
Super User

@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




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam 

It worked. Thanks alot !!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors