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

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

Reply
Anonymous
Not applicable

Calculate Day Diff between 2 dates on row level

Hi there,

 

I hope you can help me!

 

I have an issue: I used the table below as an example

 

I am trying to calculate the day difference based on " Change Date " for each Product based on " Entry NO ". Normally if I had 2 date columns that would be easy, but in this case, I have only 1 date column with all change dates.

 

It's easy to solve this in excel, but how can I solve this in Power BI? it has to be dynamic.

 

Product Entry      NoPhase      Change Date

Bike1Start8/11/2020
Bike2Develop8/12/2020
Bike3Finish8/14/2020
Car1Start8/12/2020
Car2Develop8/15/2020
Motor1Start8/17/2020
Motor2Develop8/20/2020
Motor3Finish8/24/2020
Step1Start8/11/2020
Step2Develop8/20/2020
Step3Finish8/29/2020
1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Anonymous 

 

Please check the below code. This gives 1 day as per your need.

 

CHANGE DATE = DATEDIFF([PHASE],MAXX(FILTER(TABLE,[PRODUCT] = EARLIER(PRODUCT) && [ENTRY] < EARLIER([ENTRY])),[PHASE] ),DAY)

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

HI @Anonymous 

 

Please check the below code. This gives 1 day as per your need.

 

CHANGE DATE = DATEDIFF([PHASE],MAXX(FILTER(TABLE,[PRODUCT] = EARLIER(PRODUCT) && [ENTRY] < EARLIER([ENTRY])),[PHASE] ),DAY)

 

amitchandak
Super User
Super User

@Anonymous , Not very clear

Try like

datediff(maxx(filter(table,[Product] = earlier(Product ) && [Entry] < earlier([Entry])),[Change Date] ),[Change Date],day)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

What is expect is the difference in days for each product based on entry no and change date.

 

Example,

 

Bike has 3 entry no, the difference in days = 

Change date entry no 2 - Change date entry no 3 = (12-8-2020) - (11-8-2020) = 1 day.

 

This should be dynamic where Power BI takes into consideration the Product, Entry No before calculating the diff date in days.

parry2k
Super User
Super User

@Anonymous what you are expecting #2 - #1, #3 - #2 



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.

Anonymous
Not applicable

What is expect is the difference in days for each product based on entry no and change date.

 

Example,

 

Bike has 3 entry no, the difference in days = 

Change date entry no 2 - Change date entry no 3 = (12-8-2020) - (11-8-2020) = 1 day.

 

This should be dynamic where Power BI takes into consideration the Product, Entry No before calculating the diff date in day.

@Anonymous try this measure

 

New Measure = 
VAR __entry = MAX ( Table[Entry] ) - 1
VAR __prevDate = CALCULATE ( MAX ( Table[ChangeDate] ), Table[Entry] = __entry )
RETURN
DATEDIFF ( __prevDate, MAX ( Table[ChangeDate] ), DAY )

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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.

Anonymous
Not applicable

@parry2k  Thank you.

 

the function might be correct but we have different Scenario's:

 

1. Entry No different but Change date is the same

2. Entry No not ascending (1 3 4 6 instead of 1 2 3) which means Entry No -1 won't work properly.

3. Entry No not ascending and date is the same

4. First Entry No row date diff should always be 0 because there is no previous Entry No.

5. Entry No might start at 3 instead of 1.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.