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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Eric_Tribble
New Member

DATEDIFF with multiple criteria

OK So Im learning Power Bi.

So I have a table that has multiple Id's (LID) and it logs when that particular LID reashes a status in our system.

So I made a Max(Date) in the main table and it works good (max due to the LID can be switched back to a previous status multiple times so I need the most recent date)

What I am trying to accomplish is to get the day count between cetrin status.

Eric_Tribble_0-1643998806325.png

So you can see that this LID was in 5 different statuses. So just so I can get the basic formula down can someone help me get the following:

DATEDIFF for the LID = 'zzrRz9d5Rvrn' from 'New Lead' (11/26/21) to 'Awaiting Documents' (12/10/21)

 

The result in Table2 under 'New to AwaitDocs' should be 14 (indicating 14 days between 11/26/21 and 12/10/21)

 

I have to do this between multiple different statuses but just asking for a general formula for the above, after that I should be able to figure it out from there.

Please and Thank you!

 



3 REPLIES 3
tackytechtom
Super User
Super User

Hi @Eric_Tribble ,

 

First add an index to your table in Power Query:

tomfox_0-1644005719564.png

 

After that you can create a calculated column with this code:

TomsNewColumn = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[LDate] ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    ),
    'Table'[LDate],
    DAY
)

 

You should end up with something like this depending on the index:

tomfox_1-1644006281173.png

 

 

Did this do the trick for you? 🙂

 

/Tom

https://www.tackytech.blog

https://www.instagram.com/tackytechtom

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Is there a way to make the Index pull from a list so I can assign the status's in order?
1= New,

2=awaiting docs,

3=STR Review Call,

etc

My end result would probaly me a matrix type table

LID List |  Status 1  |   Status 2    |   Status 3   | 

__________________________________________________________

LID1     | startDate | 2-1 = Days | 3-2 = Days | 

 

somthing like that

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.