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

Reply
Anonymous
Not applicable

Merge two tables on ID and if before or after date?

I have two tables, a transaction table and a customer table. I make a relationship on the tables based on cusotmer id. But if the customer changes thier address this causes issues as now they are associted with multiple addresses when looking up an order. I want to be able to see the customer info at the time of the transaction. 

Transaction Table

OrderIdCustomerIdValueTransaction_Date
99912310,99910/11/2021
88945659993/5/2021

Customer Table

CustomerIDAddresslast_change_date
123123 N North Street10/8/2021
456456 W West Street2/14/2021
123789 E East Street1/10/2021

The way it is now is id I wanted to make a the adress for customer 123 dor order 999 it would pull both address we have for the customer. But I want it to be albe to check both cusotmerID and compare the order_Date and check that the order_Date is within the range of of the last_change _dates. 

8 REPLIES 8
smpa01
Super User
Super User

@Anonymous  you can use a measure like this

_Address = 
CALCULATE (
    MAX ( Customer[Address] ),
    FILTER (
        VALUES ( Customer[last_change_date] ),
        Customer[last_change_date] <= MAX ( 'Transaction'[Transaction_Date] )
    )
)

 

smpa01_0-1637990552351.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@Anonymous  did you have a chance to try out the above?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01 Yes, I seems to work for some. So one customer could have like 5 differnt adresses over the apst 10 years. And when I use this mesure it only populates 2-3 addresses and the others are left blank. The logic seems sound so Im not sure why its doing that. 

@Anonymous  can you please provide some example

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01 

I changed the  dummy data to fit a bit more to my real data. This is what I get. 

Customer_History

NotRick_0-1638822713184.png

Order_History

NotRick_1-1638822746744.png

What I got is same address for every order. Even for customer who isnt assoctiated with that address. 

NotRick_3-1638822934673.png

 

 

@Anonymous  please post sample data in table format.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01 

I changed the  dummy data to fit a bit more to my real data. This is what I get. 

Customer_History

NotRick_0-1638822713184.png

Order_History

NotRick_1-1638822746744.png

What I got is same address for every order. Even for customer who isnt assoctiated with that address. 

NotRick_3-1638822934673.png

 

 

lbendlin
Super User
Super User

Your sample data doesn't cover all possible scenarios.  Please extend it if possible.

 

I would recommend to separate customers and customer addresses into different tables .

 

Why would a transaction care if the customer's address has changed? Different shipping costs?

Helpful resources

Announcements
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

PBI_APRIL_CAROUSEL1

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