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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Islem
New Member

Merge table with a condition with power query

Hi guys,

I have two table, the 1st contains customers with sales and date and the second contains sales responsible with assigned customer and date

how can I merge both tables to get the right sales person who dealed with customers in a specific period 

 

1st table 

1.PNG

 

2nd table 

 

2.PNG

Result should be the following 

3.PNG

1 ACCEPTED SOLUTION

Hi @Islem 

 

You can first merge Table 2 to Table 1 by Customer column. This will add a [Table 2] column in Table 1. 

vjingzhang_0-1677046546940.png

Then add a custom column with below code. This will get the responsible sales person in corresponding period. 

let _salesDate = [Date] in Table.Last(Table.Sort(Table.SelectRows([Table 2], each [Date] <= _salesDate), {"Date", Order.Ascending}))[Sales responsible]

vjingzhang_1-1677046649353.png

After that, remove the [Table 2] column from Table 1. PBIX file has been attached at bottom. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
bhelou
Responsive Resident
Responsive Resident

Hello , 

try to clean the data you want to combine to : meaninng to combine 2 tables or more they should have the same column name and sometimes same discription to be merged , 

clean the second table , split the columns then do the merge . 

if you can provide a sample with the data , ill try to solve it to you . 

Hi,

Can you check the post again please

Hi @Islem 

 

You can first merge Table 2 to Table 1 by Customer column. This will add a [Table 2] column in Table 1. 

vjingzhang_0-1677046546940.png

Then add a custom column with below code. This will get the responsible sales person in corresponding period. 

let _salesDate = [Date] in Table.Last(Table.Sort(Table.SelectRows([Table 2], each [Date] <= _salesDate), {"Date", Order.Ascending}))[Sales responsible]

vjingzhang_1-1677046649353.png

After that, remove the [Table 2] column from Table 1. PBIX file has been attached at bottom. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

great solution, many thanks dear

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.