Forum Discussion
Custom Column - Value from other query
- Anonymous6 years agoJust do this:
Table.AddColumn(PrevStep, “NewColumnName”, each OtherTable[ColumnName]{2})
//{2} being the zero-based position of the other table’s item that you want. You could also do
each OtherTable[ColumnName] = “Some Team”, type text).
I cannot work on it without the source files. When I go into Power Query it says Clubs.xlsx and Sample Table.xlsx are missing.
Just looking though at the data in the DAX model (and I would not do any merge in DAX), you have no filed to merge on, like a customer number, index, or anything else. You cannot say "column 1, row 3" as Power Query has tables, and tables have no concept of row numbers or addressable cells like Excel spreadsheets do.
You should read this article to understand how a Merge works. You can make it somewhat analogous to how a VLOOKUP works. You want to look up this value in that table, then return in formation from that table. VLOOKUP doesn't understand row numbers either, it just needs a field to scan through and find. That is how a merge works.
Thanks edhans again for helping out.
I had a look at the article on Merging, and I have merged queries before, however I wasn't sure how to do it in this instance to achieve the desired result.
Here is a link to the file with no external links to source files so hopefully the Queries remain in tact for you:
https://www.dropbox.com/s/ou2phsdyojbx14s/Sample%20Power%20BI%20R1.pbix?dl=0
Is it possible for you to please show the steps in this file on how the Merge would work to achieve the desired result?
Thanks.
- edhans6 years agoCommunity Champion
See the attached PBIX file here.
I'm not clear on the purpose here. Your table already had the club name so not sure why you wanted to get the club name merged from the other table.
If the goal is to get the club name there in the first place, you need some way to link the two tables. In other words, how should a computer know that Club 3 is what goes in your column? You've given it no other info to make that determination.
If I'm misunderstanding, please let me know. If the merge example is what you needed, please mark this as a solution.
- artemus6 years agoMicrosoft Employee
Assuming you want to glue the other table vertically you can try this (Add custom step):
= #table(type table Type.ForRecord(Type.RecordFields(Type.TableRow(Value.Type(PreviousStep))) & Type.RecordFields(Type.TableRow(Value.Type(OtherTable))), false), List.Transform(List.Zip({Table.ToRows(PreviousStep), Table.ToRows(OtherTable)}), each _{0} & _{1}))Replace PreviousStep with the previous step in your query, and OtherTable with your other table.
- MC46 years agoFrequent Visitor
Thanks artemus - This feels close to what I am trying to do.
I have added your suggested custom step as a formula to my custom column. However, when I do this, the "Club Name" column in Table 2 is populated with "Table" and not the desired "Club 3".
This may be a result of how I have translated the Custom Step you provided.
Here is a link to the file in which perhaps you can see how I have attempted to transalte your custom step
https://www.dropbox.com/s/6qlfvrdw5h8cwz6/Sample%20Power%20BI%20R1.pbix?dl=0
Thanks!
- MC46 years agoFrequent Visitor
Thanks again edhans
The reason I want to be able to get the club name from the other table is because I want to apply this step in multiple queries with different club names and be able to update the source data from say "Club 3" to "Manchester United" and have this flow through all the queries.
So essentially I am trying to find someway to link the two tables so the computer knows to look at Club 3 from the other table.
Thanks.
- edhans6 years agoCommunity Champion
But why do you expect it to know which is Club 3 vs Club 2? How are you linking the data?