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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
WorkHard
Helper V
Helper V

How to merge the results from two tables and flatten them for each row from the second?

What is the easiest way to flatten two tables and merge them into one while retaining all the rows from the first.

For example:

I have a Projects table like this:

Project TableProject ID...Other fields
Project 11data
Project 22data
Project 33data

 

And an employee table like this:

Employee TableAssigned to Project IDEmployee Role
John1Tech
John2Tech
Andy2Tech
John1Manager
Andy2Manager
Mike2Manager

 

How do I merge the two and create a row for each employee but also retain the rows from the Projects table that do not have a match in the employee table: (bonus if I can also retain the Employees that are not in the Project List). I know, the data is a mess.

Results tableProject IDEmployee NameEmployee Role...Other Fields
Project 11JohnTechdata
Project 11JohnManagerdata
Project 22JohnTechdata
Project 22AndyTechdata
Project 22AndyMangerdata
Project 22MikeManagerdata
Project 33   
1 ACCEPTED SOLUTION

@WorkHard 

here is a DAX workaround for you

Table = 
VAR pro=DISTINCT('project'[Project ID])
VAR emp=DISTINCT(employee[Assigned to Project ID])
VAR tbl=EXCEPT(pro,emp)
VAR tbl2= FILTER(project,project[Project ID]=tbl)
VAR tbl3=ADDCOLUMNS( tbl2,"Emplyee Name",blank(),"Other Field",blank())
VAR tbl4 =SELECTCOLUMNS( FILTER( ADDCOLUMNS( CROSSJOIN(project,employee),"check",if(project[Project ID]=employee[Assigned to Project ID],1,0)),[check]=1),"Project Table",project[Project Table],"Project ID",project[Project ID],"Employee Name",employee[Employee Table],"Employee Role",employee[Employee Role],"other Fields",project[...Other fields])
return UNION(tbl3,tbl4)

1.png





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
ryan_mayu
Super User
Super User

@WorkHard 

maybe you can try merge in pq

1.PNG

 

expand columns

 

2.PNG3.PNG





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

Proud to be a Super User!




Hi @ryan_mayu , sorry, this table is a calculated UNION table and I can't access pq. Can this be done using DAX?

@WorkHard 

here is a DAX workaround for you

Table = 
VAR pro=DISTINCT('project'[Project ID])
VAR emp=DISTINCT(employee[Assigned to Project ID])
VAR tbl=EXCEPT(pro,emp)
VAR tbl2= FILTER(project,project[Project ID]=tbl)
VAR tbl3=ADDCOLUMNS( tbl2,"Emplyee Name",blank(),"Other Field",blank())
VAR tbl4 =SELECTCOLUMNS( FILTER( ADDCOLUMNS( CROSSJOIN(project,employee),"check",if(project[Project ID]=employee[Assigned to Project ID],1,0)),[check]=1),"Project Table",project[Project Table],"Project ID",project[Project ID],"Employee Name",employee[Employee Table],"Employee Role",employee[Employee Role],"other Fields",project[...Other fields])
return UNION(tbl3,tbl4)

1.png





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

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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