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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
dw700d
Post Patron
Post Patron

Calculating date difference

I’m not sure if this is possible in power bi. But if it is I could use some guidance. I am trying to calculate the difference between two dates. The first date is a purchase date. The second date is a payment date. Purchase dates have one date per order number. Payment dates can have one date per order number or multiple dates per order number. For example, on 1/1/2020 I purchased an item and then I made payments  on three separate occasions in March, April and May. How do I calculate the difference between the purchase date and the most recent payment date?

 

 

Order numberpurchase datecost
11/1/2020300
21/2/2020400
31/3/2020100
41/4/2020500
51/5/2020900
61/6/2020250
71/7/2020100
81/8/2020400
91/9/2020100
101/10/2020150
111/11/2020200
121/12/2020300

 

Order numberPayment Date                 cost         
13/1/2020100
14/5/2020100
15/1/2020100
22/2/2020400
43/2/2020300
43/2/2020100
43/2/2020100
63/22/2020150
74/1/202050
74/2/202050
85/2/2020200
85/8/2020200
1 ACCEPTED SOLUTION
v-xulin-mstf
Community Support
Community Support

Hi @dw700d,

 

Try measure as:

Measure =

var _date1=

CALCULATE(

    MAX(Table1[purchase date]),

    FILTER(

        Table1,

        Table1[Order number]=MAX(Table2[Order number])

    )

)

var _date2=

CALCULATE(

    MAX(Table2[Payment Date                 ]),

    FILTER(

        ALL(Table2),

        Table2[Order number]=MAX(Table2[Order number])))

return

DATEDIFF(_date1,_date2,DAY)

Here is the output:

v-xulin-mstf_0-1611732680841.png

 

Here is the demo, please try it: Calculating date difference

Best Regards,

Link

View solution in original post

3 REPLIES 3
v-xulin-mstf
Community Support
Community Support

Hi @dw700d,

 

Try measure as:

Measure =

var _date1=

CALCULATE(

    MAX(Table1[purchase date]),

    FILTER(

        Table1,

        Table1[Order number]=MAX(Table2[Order number])

    )

)

var _date2=

CALCULATE(

    MAX(Table2[Payment Date                 ]),

    FILTER(

        ALL(Table2),

        Table2[Order number]=MAX(Table2[Order number])))

return

DATEDIFF(_date1,_date2,DAY)

Here is the output:

v-xulin-mstf_0-1611732680841.png

 

Here is the demo, please try it: Calculating date difference

Best Regards,

Link

Ashish_Mathur
Super User
Super User

Hi,

In the first table, you may write this calculated column formula

Most recent date = calculate(max('table2'[Payment Date]),filter('table2','table2'[Order Number]=earlier('table2'[Order Number])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@dw700d add the following column, assuming these two tables are linked on Order Number

 


Days = 
VAR __pmtTable = CALCULATE ( MAX ( 'PaymentTable'[Payment Date] ) )
RETURN
DATEDIFF ( PurchaseTable[purchase date], __pmtTable, DAY )

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.