Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
jts_
Helper I
Helper I

HELP! DAX Calculation: Many to many relationship

Hi! I am new to DAX, and am struggling to have a creative way for looking up the most recent service date when customer paid thier payments.


The requirements are as below:

 

There are 2 tables, Service and Payment (I do not set up any connectivity between them in data model now)

- Service

Service DateCustomr_ID
9/1/2022101
9/5/2022103
9/15/2022101
9/20/2022102
10/1/2022103
10/15/2022102

-Payment

Payment_DateCustomer_IDAmount($)Most_Recent_Service_Date

9/1/2022

101209/1/2022
9/9/20221031009/5/2022
9/21/20221011509/15/2022
10/1/20221033510/1/2022
10/11/2022102109/20/2022
10/18/20221021010/15/2022

 

 

A customer can complete multiple services, and a customer can pay ON or AFTER their service.

Due to the fact that there is a gap between 2 tables, showing payment was paid for which service date. I am looking for writing a dax to calculate the most recent service date that is <= the pyament date per customer.

 

Column of "Most Recent Service Date" is my hopful output.

Thank you so much in advance! I am looking forward to any possible solutions!

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi  @jts_ ,

Pls test the below dax to create a new column:

Column = CALCULATE(MAX(Service[Service Date]),FILTER(Service,Service[Service Date]<=Payment[Payment_Date]&&Service[Customr_ID]=Payment[Customer_ID]))

Output result:

vluwangmsft_0-1666946464811.png

 

Best Regards

Lucien

View solution in original post

2 REPLIES 2
v-luwang-msft
Community Support
Community Support

Hi  @jts_ ,

Pls test the below dax to create a new column:

Column = CALCULATE(MAX(Service[Service Date]),FILTER(Service,Service[Service Date]<=Payment[Payment_Date]&&Service[Customr_ID]=Payment[Customer_ID]))

Output result:

vluwangmsft_0-1666946464811.png

 

Best Regards

Lucien

Hi @v-luwang-msft ,

I appreciate your solution, Lucien! Thanks a lot!!!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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