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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
bmcminn
Helper II
Helper II

Using M language, how to duplicate a column from one table in another table

I know this should be straightforward, but how do I duplicate a column from one table in another table? In the orginal table it is a whole number that comes from subtracting one date from another and then dividing by seven to get number of weeks. I tried

#"Added Custom" = Table.AddColumn(#"Added Week Date", "Week to Semester", each #"5_19_23 Current Raw Data"[Week to Semester]),

 

but that yields a list of the original column in each cell.

bmcminn_0-1684814197184.png


I tried copy and paste too, that didn't seem to work. Thanks. Maybe @MarcelBeug has an idea. I learned how to make a reference data parameter in another question he answered.

1 ACCEPTED SOLUTION

I ended up using a very simple solution because it was all just a syntax problem. What worked to copy a value from one table and from a particular cell into every other cell of a new column in a different table:

let
  Source = stuff,
  #"Other stuff",
  #"Added Columnn w/ Copied Value" = Table.AddColumn(#"Other stuff", "Columnn w/ Copied Value", each #"That Other Table"[Target Column]{0})
in
  #"Added Week of Year 2023"

with {0} being the index value.

View solution in original post

3 REPLIES 3
bmcminn
Helper II
Helper II

So I should rephrase this. I have a column in TableA with a repeating value, 20, that is calculated using some other columns. I want to copy that value and put it into a column in TableB. Becuase of the requirements of the project, this need to be done using M language so that the steps can be replicated automatically as the data refreshes and the value in TableA changes.

This morning I tried

#"Added Custom" = Table.AddColumn(#"Added Application Semester", "Calendar Week Copy", each "5/19/23 Current Raw Data"[Calendar Week]{1})

and I can imagine that the error is the same as @danextian mentions above, but I don't understand how to use the filter logic.

Thank you.

I ended up using a very simple solution because it was all just a syntax problem. What worked to copy a value from one table and from a particular cell into every other cell of a new column in a different table:

let
  Source = stuff,
  #"Other stuff",
  #"Added Columnn w/ Copied Value" = Table.AddColumn(#"Other stuff", "Columnn w/ Copied Value", each #"That Other Table"[Target Column]{0})
in
  #"Added Week of Year 2023"

with {0} being the index value.

danextian
Super User
Super User

Hi @bmcminn ,


The below script creates a list based on [Week to Semester] column from "5_19_23 Current Raw Data" table.

#"5_19_23 Current Raw Data"[Week to Semester]

You did not specify how to identify which row/s in the created list each row in the current table should pick thus you end up with the same information for  each row. You can either do a merge or use the same list but specify a filter logic similar to below

let 
lookupvalue = [column in the current table],
lookupcolumn = othertable[lookup column], 
resultcolumn = othertable[result column]
in resultcolumn{List.PositionOf(lookupcolumn,lookupvalue]}

The above code as a custom column determines the row position of the lookupvalue and picks up the value of that position from the  resultcolumn list. Position of the first row is zero.

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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