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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
M_SBS_6
Helper V
Helper V

Delivery Days

Hi,
I am trying to track the number of days for a delivery status.

Below is my current table. I'd like to track the number of days between each date with the first date showing as a BLANK.

This is my current table. I do have records prior to 2024 but I'm only interested in what happens from 2024 onwards.

Name.  Status.  Date
Test1.    Nores.  03/01/2024
Test2.    Nores.  05/01/2024
Test3.    Delivery1 10/01/2024
Test4.    Delivery2  12/01/2024

This is my table with the additional column added.

Name.  Status.  Date.               Days
Test1.    Nores.  03/01/2024   (blank)
Test2.    Nores.  05/01/2024.       2
Test3.    Delivery1 10/01/2024.   5
Test4.    Delivery2 12/01/2024.   2

Any idea how I can go about doing this please?

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

Hi @M_SBS_6 ,

 

@Greg_Deckler  provided a good solution. I have another method here. I hope it will be helpful to you.


1. After sorting the dates in ascending order in power query, create an index column.

vkaiyuemsft_0-1710315632597.png


2. Create a calculated column and write an expression.

Column =
VAR _pre = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Index] = EARLIER('Table'[Index]) - 1))
RETURN
DATEDIFF(_pre,'Table'[Date],DAY)


3. If you don’t need the index column, you can click the little eye next to the column name to hide it.

vkaiyuemsft_1-1710315673907.png

 

vkaiyuemsft_2-1710315673916.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-kaiyue-msft
Community Support
Community Support

Hi @M_SBS_6 ,

 

@Greg_Deckler  provided a good solution. I have another method here. I hope it will be helpful to you.


1. After sorting the dates in ascending order in power query, create an index column.

vkaiyuemsft_0-1710315632597.png


2. Create a calculated column and write an expression.

Column =
VAR _pre = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Index] = EARLIER('Table'[Index]) - 1))
RETURN
DATEDIFF(_pre,'Table'[Date],DAY)


3. If you don’t need the index column, you can click the little eye next to the column name to hide it.

vkaiyuemsft_1-1710315673907.png

 

vkaiyuemsft_2-1710315673916.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@M_SBS_6 See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the suggestion but unfortunately, I can't seem to work it out. 

@M_SBS_6 PBIX is attached below signature:

Column = 
  VAR __Current = [Date]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < __Current),[Date])
  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Date])
  VAR __Result = IF(__PreviousDate = BLANK(), BLANK(), ( __Current - __Previous ) * 1.)
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you. Mine still doesn't work though, my first row populates with a 1 and I can't understand why that is. Im using the exact code you sent. 

Helpful resources

Announcements
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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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