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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Renstrom
New Member

How to use DATEDIFF with different conditions

Hello,

 

I am a beginner with Power BI and DAX from Sweden that really need your help. I have watched a lot of youtube about DAX and experimented a lot but now im stuck..

I have searched for an awnser but cant find a simular issue so now im turning to the experts 🙂

 

So I have a table with all orders that I have in the system. When the order is created it gets a date. When the customers give a call and tells us the order is ready for templating the order status is changed to "Template booked" and gets a new date. This could be 1 week up to like 50 weeks before it happens.

So i need to know how many weeks/days it is for a order to go from "Created" to "Template booked".

 

 

Column DOCINDEX is the value that is the same on the order.

Renstrom_0-1680939352782.png

 

Thank you in advance!

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Renstrom 

please try

Process Days =
VAR CurrentEndDate = 'Table'[Slutdatum]
VAR CurrentIndexTable =
CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[DOCINDEX] ) )
VAR StartDate =
MAXX ( CurrentIndexTable, 'Table'[Startdatum] )
VAR EndDate =
COALESCE ( MAXX ( CurrentIndexTable, 'Table'[Slutdatum] ), StartDate )
RETURN
IF ( CurrentEndDate <> BLANK (), DATEDIFF ( StartDate, EndDate, DAY ) )

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Renstrom 

please try

Process Days =
VAR CurrentEndDate = 'Table'[Slutdatum]
VAR CurrentIndexTable =
CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[DOCINDEX] ) )
VAR StartDate =
MAXX ( CurrentIndexTable, 'Table'[Startdatum] )
VAR EndDate =
COALESCE ( MAXX ( CurrentIndexTable, 'Table'[Slutdatum] ), StartDate )
RETURN
IF ( CurrentEndDate <> BLANK (), DATEDIFF ( StartDate, EndDate, DAY ) )

Wow, many thanks, you are awesome!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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