cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
heytherejem Member
Member

Referencing columns from tables in Query Editor

Good morning,

 

I have two tables I've pulled through to Power BI from SQL servers. The Table names are "QueryCMWritten" and "QueryPM Written"

I want to create a new table, pulling through some columns from both tables. 

I created a blank table called Variance - see attached image. 

Say I want to pull a column through called "Column1CM" and "Column1PM" from these two tables. Is this possible? And if so, what M code do I write to do this?

 

Thanks!

Jemma

 

NewTable.png

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support Team
Community Support Team

Re: Referencing columns from tables in Query Editor

Hi @heytherejem,

 

By my tests, you could use Table.SelectColumns() fucntion to get the columns from another table.

 

Here is my test sample.  

 

Assuming that I have two tables Sheet1 and Sheet6, then I create the blank query and type the query below.

 

 

let
    Source = Table.SelectColumns(Sheet6,"PostingYear"),
in
    Source

Then I will get the column [Posting Year] from table Sheet 6. Then I could create the custom column with the same query.

 

 

 

let
    Source = Table.SelectColumns(Sheet6,"PostingYear"),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Table.SelectColumns(Sheet1,"TYPE")),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"TYPE"}, {"Custom.TYPE"})
in
    #"Expanded Custom"

 

 

The query above should make sense of you. I'm not good at M query.

 

Hope @ImkeF would help you get the solution more efficient.

 

Best  Regard,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Super User
Super User

Re: Referencing columns from tables in Query Editor

Usually, I would merge 2 tables via a common key-column to make sure that each row has data that belongs together (see here for example: https://www.powerquery.training/portfolio/merge-tables/).

 

But if you really just want to put one table beneath the other, you'd use Table.ToColumns on each of those tables and create a joined table using Table.FromColumns(TransformedFirstTable & TransformedSecondTable)

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

Proud to be a Datanaut!

Imke Feldmann

How to integrate M-code into your solution -- Check out more PBI- learning resources here -- Performance Tipps for M-queries




View solution in original post

3 REPLIES 3
Community Support Team
Community Support Team

Re: Referencing columns from tables in Query Editor

Hi @heytherejem,

 

By my tests, you could use Table.SelectColumns() fucntion to get the columns from another table.

 

Here is my test sample.  

 

Assuming that I have two tables Sheet1 and Sheet6, then I create the blank query and type the query below.

 

 

let
    Source = Table.SelectColumns(Sheet6,"PostingYear"),
in
    Source

Then I will get the column [Posting Year] from table Sheet 6. Then I could create the custom column with the same query.

 

 

 

let
    Source = Table.SelectColumns(Sheet6,"PostingYear"),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Table.SelectColumns(Sheet1,"TYPE")),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"TYPE"}, {"Custom.TYPE"})
in
    #"Expanded Custom"

 

 

The query above should make sense of you. I'm not good at M query.

 

Hope @ImkeF would help you get the solution more efficient.

 

Best  Regard,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Super User
Super User

Re: Referencing columns from tables in Query Editor

Usually, I would merge 2 tables via a common key-column to make sure that each row has data that belongs together (see here for example: https://www.powerquery.training/portfolio/merge-tables/).

 

But if you really just want to put one table beneath the other, you'd use Table.ToColumns on each of those tables and create a joined table using Table.FromColumns(TransformedFirstTable & TransformedSecondTable)

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

Proud to be a Datanaut!

Imke Feldmann

How to integrate M-code into your solution -- Check out more PBI- learning resources here -- Performance Tipps for M-queries




View solution in original post

Community Support Team
Community Support Team

Re: Referencing columns from tables in Query Editor

Hi @heytherejem ,

 

Have you solved your problem?

 

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If you still need help, please feel free to ask.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 145 members 1,529 guests
Please welcome our newest community members: