Forum Discussion
cscollier2
3 years agoNew 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...
BA_Pete
3 years agoSuper 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 =
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