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
Hannes_Corbett
New Member

How to connect the same value to multiple rows from the same table

Hi,

 

Currently trying to setup a PowerBI report from a document storage system I've got.

 

So in one table I've got the almost all the data such as

VM_DOCUMENT (table name)

  • Author ID
  • Owner ID
  • Approver ID
  • 2nd Approver ID
  • Document Name
  • Document Code

And in another table I've got the Role ID that gives what the Role is called and their name

VM_ROLE (table name)

  • Role ID
  • Role Name
  • First Name
  • Last Name

I want to be able to get so I can get the ones in VM_DOCUMENT to each show the VM_ROLE in different places.

 

For example, I want to be able to have a row with the Document Name, Author Name, Owner Name, Approver Name and 2nd Approver Name.

 

But I can only manage to do a connection to one of the things listed in VM_DOCUMENT and not one that is seperate to each one.

 

My guess is that I've got to create new table in some way but unsure how to do this.

 

Please let me know if you need more information or have a solution.

 

Kind regards,

Hannes

1 ACCEPTED SOLUTION
Claude_Xu
Frequent Visitor

Hi Hannes,

 

Not sure if I understand your question clearly. Providing some sample data and output will be helpful.

 

If you just need information like FirstName and LastName from VM_ROLE  to be 'merged' into Author, Owner, Approver and 2nd Approver of VM_DOCUMENT, one dummy solution is to do table join multiple times. One trick here is to rename the VM_ROLE table by prefixing it because duplicate named columns are not allowed in the join result. 

 

For demonstration purpose, I use Excel but it should be almost identical to the case of Power BI. Suppose we have below data

VM_Tables.png

 

Use below M code

let
DocumentTable = Excel.CurrentWorkbook(){[Name="VM_DOCUMENT"]}[Content],
RoleTable = Excel.CurrentWorkbook(){[Name="VM_ROLE"]}[Content],
// Popualte Full Name
RoleTableWithFullName = Table.AddColumn(RoleTable, "FullName", each [FirstName] & " " & [LastName]),
// Prefix for Author join
AuthorRoleTable = Table.PrefixColumns(RoleTableWithFullName, "Author"),
#"Join Author Name" = Table.Join(DocumentTable, "AuthorID", AuthorRoleTable, "Author.RoleID", JoinKind.Inner),
// Prefix for Owner join
OwnerRoleTable = Table.PrefixColumns(RoleTableWithFullName, "Owner"),
#"Join Owner Name" = Table.Join(#"Join Author Name", "OwnerID", OwnerRoleTable, "Owner.RoleID", JoinKind.Inner),
// Prefix for Approver
ApproverRoleTable = Table.PrefixColumns(RoleTableWithFullName, "Approver"),
#"Join Approver Name" = Table.Join(#"Join Owner Name", "ApproverID", ApproverRoleTable, "Approver.RoleID", JoinKind.Inner),
// Prefix for 2ndApprover
SecondApproverRoleTable = Table.PrefixColumns(RoleTableWithFullName, "2ndApprover"),
#"Join 2nd Approver Name" = Table.Join(#"Join Approver Name", "2ndApproverID", SecondApproverRoleTable, "2ndApprover.RoleID", JoinKind.Inner),
#"Select Desired Columns" = Table.SelectColumns(#"Join 2nd Approver Name", {"DocumentName", "DocumentCode", "Author.FullName", "Owner.FullName", "Approver.FullName", "2ndApprover.FullName"})
in
#"Select Desired Columns"

we can get below result

VM_JoinResult.png

 

Obviously, there are duplicate lines of code to do the join operation for Author, Owner, Approver and 2ndApprover. A better way to handle that is to extract the duplicate code and form a function in M. But anyway, I think you get the basic idea here.

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Feels like at least you need a Persons Dimension table, a Roles Dimension table, and a Role Assignments fact table.

Claude_Xu
Frequent Visitor

Hi Hannes,

 

Not sure if I understand your question clearly. Providing some sample data and output will be helpful.

 

If you just need information like FirstName and LastName from VM_ROLE  to be 'merged' into Author, Owner, Approver and 2nd Approver of VM_DOCUMENT, one dummy solution is to do table join multiple times. One trick here is to rename the VM_ROLE table by prefixing it because duplicate named columns are not allowed in the join result. 

 

For demonstration purpose, I use Excel but it should be almost identical to the case of Power BI. Suppose we have below data

VM_Tables.png

 

Use below M code

let
DocumentTable = Excel.CurrentWorkbook(){[Name="VM_DOCUMENT"]}[Content],
RoleTable = Excel.CurrentWorkbook(){[Name="VM_ROLE"]}[Content],
// Popualte Full Name
RoleTableWithFullName = Table.AddColumn(RoleTable, "FullName", each [FirstName] & " " & [LastName]),
// Prefix for Author join
AuthorRoleTable = Table.PrefixColumns(RoleTableWithFullName, "Author"),
#"Join Author Name" = Table.Join(DocumentTable, "AuthorID", AuthorRoleTable, "Author.RoleID", JoinKind.Inner),
// Prefix for Owner join
OwnerRoleTable = Table.PrefixColumns(RoleTableWithFullName, "Owner"),
#"Join Owner Name" = Table.Join(#"Join Author Name", "OwnerID", OwnerRoleTable, "Owner.RoleID", JoinKind.Inner),
// Prefix for Approver
ApproverRoleTable = Table.PrefixColumns(RoleTableWithFullName, "Approver"),
#"Join Approver Name" = Table.Join(#"Join Owner Name", "ApproverID", ApproverRoleTable, "Approver.RoleID", JoinKind.Inner),
// Prefix for 2ndApprover
SecondApproverRoleTable = Table.PrefixColumns(RoleTableWithFullName, "2ndApprover"),
#"Join 2nd Approver Name" = Table.Join(#"Join Approver Name", "2ndApproverID", SecondApproverRoleTable, "2ndApprover.RoleID", JoinKind.Inner),
#"Select Desired Columns" = Table.SelectColumns(#"Join 2nd Approver Name", {"DocumentName", "DocumentCode", "Author.FullName", "Owner.FullName", "Approver.FullName", "2ndApprover.FullName"})
in
#"Select Desired Columns"

we can get below result

VM_JoinResult.png

 

Obviously, there are duplicate lines of code to do the join operation for Author, Owner, Approver and 2ndApprover. A better way to handle that is to extract the duplicate code and form a function in M. But anyway, I think you get the basic idea here.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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