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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
digitalPlay
Frequent Visitor

Calculated column with days between previous dates

I need to get the count of days between 2 dates (previous dates per row). It sort of works unless there are same dates for different categories then it will get the last non repeating date as the subtrahend. I would like to have a result where it will blank or zero for the 2nd repeating date. Any help is much appreciated 🙂

digitalPlay_0-1689167578799.png

This is what I currently use:

var temp = TOPN(1,
    FILTER('Run Rate', 'Run Rate'[Project ID] = EARLIER('Run Rate'[Project ID])
    && 'Run Rate'[Milestone Date] < EARLIER( 'Run Rate'[Milestone Date] )
),
'Run Rate'[Milestone Date])

return
DATEDIFF(MINX(temp,'Run Rate'[Milestone Date]), 'Run Rate'[Milestone Date],DAY)

 

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

Hi , @digitalPlay 

According to your description, you want to Calculated column with days between previous dates and you want to the previous same date show 0.

For your requirement, this needs to judge the row number, so we need to sort the columns in Power Query first and then create an Index column to meet the requirement.

First, we need to sort the two columns in Power Query Editor:

vyueyunzhmsft_0-1689306795612.png

Then we need to add an index column in it :

vyueyunzhmsft_1-1689306822710.png

Then we can modify your dax code like this:

Column = var temp = TOPN(1,
    FILTER('Run Rate', 'Run Rate'[Project ID] = EARLIER('Run Rate'[Project ID])
    && 'Run Rate'[Milestone Date] <= EARLIER( 'Run Rate'[Milestone Date] ) && 'Run Rate'[Index]<EARLIER('Run Rate'[Index])
),
'Run Rate'[Index])

return
DATEDIFF(MINX(temp,'Run Rate'[Milestone Date]), 'Run Rate'[Milestone Date],DAY)

 

Then we can get the result as follows:

vyueyunzhmsft_2-1689306861931.png

 

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

2 REPLIES 2
v-yueyunzh-msft
Community Support
Community Support

Hi , @digitalPlay 

According to your description, you want to Calculated column with days between previous dates and you want to the previous same date show 0.

For your requirement, this needs to judge the row number, so we need to sort the columns in Power Query first and then create an Index column to meet the requirement.

First, we need to sort the two columns in Power Query Editor:

vyueyunzhmsft_0-1689306795612.png

Then we need to add an index column in it :

vyueyunzhmsft_1-1689306822710.png

Then we can modify your dax code like this:

Column = var temp = TOPN(1,
    FILTER('Run Rate', 'Run Rate'[Project ID] = EARLIER('Run Rate'[Project ID])
    && 'Run Rate'[Milestone Date] <= EARLIER( 'Run Rate'[Milestone Date] ) && 'Run Rate'[Index]<EARLIER('Run Rate'[Index])
),
'Run Rate'[Index])

return
DATEDIFF(MINX(temp,'Run Rate'[Milestone Date]), 'Run Rate'[Milestone Date],DAY)

 

Then we can get the result as follows:

vyueyunzhmsft_2-1689306861931.png

 

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

awesome! thank you so much for your time and genius! you're a big help! 🙂

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.