Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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

PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors