Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
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!
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 =
CALCULATE(
// Add a variable for each dimension that you need to match on
VAR __departmentRow = VALUES(salesTable[department])
VAR __salesDateRow = VALUES(salesTable[salesDate])
RETURN
MAXX(
FILTER(
discountSCDTable,
// Match the different variables to the discountSCD table
discountSCDTable[department] = __departmentRow
&& discountSCDTable[discountStartDate] <= __salesDateRow
&& discountSCDTable[discountEndDate] >= __salesDateRow
),
discountSCDTable[discountRate]
)
)
Pete
Proud to be a Datanaut!
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 5 | |
| 4 |