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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
pxg638
Frequent Visitor

merging tables on two columns

Hi there, 

 

First post, so apologies if this is super dumb - I was either searching for the wrong thing or being exceedingly dense in understanding what others had written! I have a large (1m row) data table and a small (few hundred row) configuration table and I am trying to merge them together, thus:

 

Table.Data

Date Monthly Production Unit

31/1/20171000CNC1
31/1/20172000CNC2
31/1/20173000CNC3
28/2/20171000CNC1
28/2/20172000CNC2
28/2/20173000CNC3

 

etc

 

Table.Configuration

 

 

Date Unit Type1Jobs Type2Jobs

1/1/2017CNC10.50.5
1/2/2017CNC10.60.4
1/1/2017CNC20.50.5
1/1/2017CNC30.50.5
1/2/2017CNC301

 

In other words, for the month of Jan, CNC1 did 50% of Type1 jobs and 50% of type 2 jobs, and then in Feb was re-configured to do 60% type 1 jobs and 40% type 2 jobs.

 

The outcome I want is effectively:

 

 

Date Monthly Production Unit Type1Work Type2Work

31/1/20171000CNC1500500
31/1/20172000CNC210001000
31/1/20173000CNC315001500
28/2/20171000CNC1600400
28/2/20172000CNC210001000
28/2/20173000CNC303000

 

So the monthly production is shared out based on the fraction of the type of work, per machine. The end result I want to see is type of work over time per machine, as those get grouped by site.

 

Now, I can do a simple left outer join to achieve a baseline configuration, but I cannot do a join on two columns without getting into between/range type thinking and that is beyond my brain at this time, and therefore any configuration change of the machine is lost.

 

I see answers sort of suggesting a 2nd date table somehow, but I am struggling to see the solution. I am sure this is super simple, what am I missing?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@pxg638

 

did you guys solve it with SQL after all?

 

If so, could I ask you to accept a solution for this post, so others can benefit from it anyway?

View solution in original post

16 REPLIES 16
vanessafvg
Super User
Super User

@pxg638 why dont you create a new column, ie a key based on the combination of  both the columns?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




So I can create [Unit]&[Date] in both tables, that is simple enough, how would I then utilise that to create the change in allocation between jobtypes? Wouldn't a join on the new column simply leave lots of gaps where it didn't key up?

@pxg638 ah ok, tell me a bit more about the change in allocation, its not clear to me from your post (i might be a bit slow this morning)

 

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




So for January we do 1000 jobs. The unit is configured to do 50% type 1 and 50% type 2, so that gets 500 of the first, 500 of the second. The next month we also do 1000 jobs, but we have reconfigured the machine, so it now does 40% type 1 and 60% type 2, so I get 400 and 600 respectively. If I want to now sum my type 1 jobs, I'd like to know this unit did 900 type 1s and 1100 type 2s in the first two months. 

 

That any clearer?

Anonymous
Not applicable

Hi @pxg638

 

Could you provide column headers? I want to re-create your problem in Power BI to test a solution, I have in mind.

 

Thanks in advance.

 

Best

Martin 

@Anonymous

 

Column headers failed to show on the original post, sorry! HTML failed me! So you have reporting date, volume, and unit for the first table, then configuration date, unitname, fraction T1 work and fraction T2 work (effectively) for the 2nd table.

 

I am simplying the reality here, but the principle is presented.

Anonymous
Not applicable

 @pxg638

 

Alright, the way, I've solved this, is by generating an ID-column for linking a certain production to a certain configuration. I'm not sure whether this will accommodate your dataflow or data-setup. If you can't generate an ID-column, I suggest you tell us a little more about your challenge and data-setup, so I can figure out a suiting solution for you. The smoothest way, in my opinion, to go about your challenge is to generate an ID-column. Take a look a below picture.

 

Let me know if this solves your problem, and if we should go in a different direction.

 

Related production tables.png

@Anonymous

 

So that would work if the configuration table had an entry for every month that I had data. Right now, it doesn't, it only logs the changes. Using a [unit]&[Date.Month]&[Date.Year] key would enable this simply enough, if I had an entry for each and every month in both tables. Using that approach right now yields a huge number of null rows in the subsequent merge.

 

 

Anonymous
Not applicable

Maybe I misunderstand your reply, in which case please correct me. But you could probably duplicate configuration table for each month? It's just a new duplication when you guys have changes in the configuration table?

 

An example: Check whether there is any changes to configuration table: If there is none, duplicate last month, if there is changes duplicate those changes. Wouldn't this accommodate your problem?

 

 

Changing the source data set is harder to do than it should be. Would it be possible to duplicate those rows in a table within the analysis?

Anonymous
Not applicable

Hmm. I guess you could do it in Power Query. Maybe it's also possible with DAX, I honestly don't know. But going forward I would suggest taking this approach.

Our data team has done this in SQL Server for us as a proof of concept, so I get the end resulting table directly on SQL Server and can do my visualisation on the back of that, as opposed to trying to construct it here. Thanks for the suggestions!

Anonymous
Not applicable

@pxg638

 

I'm glad you guys have tried it out, and that it works for you. If you consider this post solved, could I ask you accept a solution?

 

Best of luck in the future,

Martin

Anonymous
Not applicable

@pxg638

 

did you guys solve it with SQL after all?

 

If so, could I ask you to accept a solution for this post, so others can benefit from it anyway?

Yeah, we did it at the DB level in the end. Thanks for the help!

Anonymous
Not applicable

The example is just fine. I had missed the headers, so thank you for providing them. I'll re-create this in Power BI now, and try out my solution. Then I'll get back to you with the results.

 

Best

Martin

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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