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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Jeanxyz
Impactful Individual
Impactful Individual

merge tables in DAX

Hi, 

 

I have two tables, there is many-to-many relationship between the two table. Is it possible to merge the columns to form a combined table in DAX?

 

Thanks!

 

merge table.PNG

8 REPLIES 8
v-eqin-msft
Community Support
Community Support

Hi @Jeanxyz ,

 

Please try:

New Table = 
var _t= CROSSJOIN('Table 2',SELECTCOLUMNS('Table 1',"Cost Center",[Cost Center],"Cost Center split factor",[Cost Center split factor]))
return ADDCOLUMNS(_t,"key",LOOKUPVALUE('Table 1'[key],'Table 1'[Pay date],[Pay period]))

Then rename the Pay period column

Eyelyn9_1-1641884756502.png

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jeanxyz
Impactful Individual
Impactful Individual

Thanks, Everlyn. However, my 2 tables are not well structured, if I use crossjoin() it will create many wrong records as it ignores the employee id relationsip. 

parry2k
Super User
Super User

@Jeanxyz I totally agree with @Ashish_Mathur . What problem you are trying to solve? Doing the merge in DAX shouldn't be a problem but is it really necessary? Let's be honest, if we know what you are trying to achieve, maybe there are better ways, so I guess, if you help us understand what you are looking for, I'm sure brilliant brains here will get you an amazing solution. Just my 2 cents.

 

P



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Jeanxyz
Impactful Individual
Impactful Individual

Yes, it will be a piece of cake to merge two tables in power query. However, Power Query also has its limitations such as slow data refreshing which makes prefer DAX in some situations. In my case, I have already created a complex pay table using DAX, as a new request, the client wants to introduce cost center and split factor to the main pay table. Therefore I have to merge table in DAX. 

Ashish_Mathur
Super User
Super User

Hi,

Why do you want to do this in DAX?  Why not in the Query Editor?  There you can simply join the 2 tables based on Employee ID and Pay Date/Period Period.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@Jeanxyz , Crossjoin, naturalinner join etc

 

refer

https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Jeanxyz
Impactful Individual
Impactful Individual

I have tried to create a merge table with the DAX  formula below and got an error message: "An incompatible join column, (''[payroll datekey]) was detected. 'NATURALINNERJOIN' doesn't support joins by using columns with different data types or lineage."

 

For your info, the joining colum is [payroll datekey], it's stored as text in both tables, so I'm not sure why the error message pops out. besides, i'm not sure if 

NATURALINNERJOIN supports many-to-many as in both tables there are multiple rows linked to one single [payroll datekey] value. 

 

merge_table =
var master=filter(SELECTCOLUMNS(Master_Resources_new,"A EE/CC ID",[A EE/CC ID],"Employee Name",[Employee Name],"Function",[Function],"Hiring Status",[Hiring Status],"Location",[Location],"Entity",[Entity],"Entity-CC Group",[Entity-CC Group],"Team",[Team],"Type of contract",[Type of Contract],"Actual Start Date",[Actual Start Date],"Actual End Date",[Actual End Date],"A OTE",[A OTE],"payroll datekey",[payroll datekey],"split",[split],"Resource Cost Check",[Resource Cost check]),[Resource Cost Check]="include")
var payroll=selectcolumns(payroll_est_group,"payroll datekey",[payroll datekey],"Pay Component",[Pay Component],"Amount",[Amount],"Currency",[Currency])
return
NATURALINNERJOIN(master,payroll)

@Jeanxyz  does this help?

merge_table =
VAR master =
    FILTER (
        SELECTCOLUMNS (
            Master_Resources_new,
            "A EE/CC ID", [A EE/CC ID],
            "Employee Name", [Employee Name],
            "Function", [Function],
            "Hiring Status", [Hiring Status],
            "Location", [Location],
            "Entity", [Entity],
            "Entity-CC Group", [Entity-CC Group],
            "Team", [Team],
            "Type of contract", [Type of Contract],
            "Actual Start Date", [Actual Start Date],
            "Actual End Date", [Actual End Date],
            "A OTE", [A OTE],
            "payroll datekey", [payroll datekey]&"",
            "split", [split],
            "Resource Cost Check", [Resource Cost check]
        ),
        [Resource Cost Check] = "include"
    )
VAR payroll =
    SELECTCOLUMNS (
        payroll_est_group,
        "payroll datekey", [payroll datekey]&"",
        "Pay Component", [Pay Component],
        "Amount", [Amount],
        "Currency", [Currency]
    )
RETURN
    NATURALINNERJOIN ( master, payroll )
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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