• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Date difference by condition

lipo_k

New Member
Hi everyone! Need a bit of help from the Power query guru.
So, I'm trying to get the last order and the previous order dates by each customer

For example, we have a table
Date of order | Customer | Manager
------------------------------------------
01.01.2023 | Customer 1 | Bob
07.01.2023 | Customer 2 | John
15.01.2023 | Customer 1 | Bob
10.02.2023 | Customer 3 | Ann
14.02.2023 | Customer 1 | Bob
20.02.2023 | Customer 2 | John
21.02.2023 | Customer 2 | John
25.02.2023 | Customer 1 | Bob

And as a result, need to get the table like
Customer | Manager | last order | Previous order | Date Difference
-----------------------------------------------------------------------------
Customer 1 | Bob | 25.02.2023 | 14.02.2023 | 11
Customer 2 | Tom | 21.02.2023 | 20.02.2023 | 1
Customer 3 | Ann | 10.02.2023 | - | 0

Maybe someone knows how to get it... Its pretty simple to write in SQL, but in M I have no idea (
 
Does a customer always have the same manager?
Its pretty simple to write in SQL
Could you show the SQL you'd use?

A quick first draft in the attached, groups by Customer and Manager.

83154

It would be better if you were to attach a workbook, saves us guessing wrongly about your data.
 

Attachments

  • Chandoo51479.xlsx
    18.7 KB · Views: 2
Back
Top