Skip to main content
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.

New Member

Merging columns from two tables

Hello, community I am reaching out with a question that has stumped me. I am attempting to merge two tables in power query to bring in additional data. I am going to let our the scenario as best as I can. Unfortunately, I cannot share the data as it is proprietary to my work. 


First Table - The first table contains several million rows of sales data for each transaction that is processed at work. This contains the date, dimension data, and the amount of the sale


Second Table - The second table contains discount rates that need to be applied to the sales transaction. However, the discount rates have a time frame when they are valid. Such as 10% from 04/2022 to 07/2022 and 15% from 08/2022 to 11/2022. 


What I am attempting to do is merge the correct discount percentages with the correct sales transaction dates. Such as any sales that occurred from 04/2022 to 07/2022 bring in a 10% value and any sales from 08/2022 to 11/2022 bring in a discount value of 15%. The problem that I run into is when merging the first table with the second on a dimension value it ends up duplicating the discount percentages because it brings in the 10% and the 15%. 


Can someone assist with this issue!

Super User
Super User

Hi @cscollier2 ,


I think you'll want to do this in DAX. Conditional merges in Power Query can be complicated and provide poor performance.

I'm normally totally against the use of DAX calculated columns, but the following is the most performant way of dealing with SCD tables I've found so far. I've got a 1M row table that I do this twice on, the second column referencing the first, and it's lightning-fast. However, I've not tested this on tables over 1M rows, so YMMV.


As a DAX calculated column on your Sales table:

..saleDiscount = 
    // Add a variable for each dimension that you need to match on
    VAR __departmentRow = VALUES(salesTable[department])
    VAR __salesDateRow = VALUES(salesTable[salesDate])
            // Match the different variables to the discountSCD table
            discountSCDTable[department] = __departmentRow
            && discountSCDTable[discountStartDate] <= __salesDateRow
            && discountSCDTable[discountEndDate] >= __salesDateRow




Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!

Helpful resources

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


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.

Top Solution Authors
Top Kudoed Authors