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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
SamBrown17
Helper I
Helper I

How to calculate Date diff with data setup

Hi Team,

 

I have the example data below,

 

I have a database full of record types which are jobs in my system, I want to calculate the average time or date difference between a set sequence of the work flow.  so for the below I want to know the average time it take to go from Book to Scheduled and so on.

 

How could I go about this? Is it through a measure? or Reconfige of the data 

 

SamBrown17_0-1645095594296.png

 

1 ACCEPTED SOLUTION

@SamBrown17 Right, it's the same principle but yours will look something like this:

Column = 
  VAR __record = [record_id]
  VAR __type = [event_type]
  VAR __current = [created_at]
  VAR __currentStatus = [To (Status)]
  VAR __previous = 
    IF(__type = "Job status updated",
      SWITCH(__currentStatus,
        "Scheduled",MAXX(FILTER('Table',[record_id] = __record && [From (Status) = "Book" && [To (Status)] = BLANK(),[created_at]),
        "Site Attended",MAXX(FILTER('Table',[record_id] = __record && [From (Status) = "Book" && [To (Status)] = "Scheduled",[created_at])
      )
    )
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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
v-henryk-mstf
Community Support
Community Support

Hi @SamBrown17 ,

 

Whether the advice given by @Greg_Deckler  has solved your confusion, if the problem has been solved you can mark the reply for the standard answer to help the other members find it more quickly. If not, please point it out.


Looking forward to your feedback.


Best Regards,
Henry

Greg_Deckler
Community Champion
Community Champion

@SamBrown17 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler   Your article was insightful however I think my situation differs slightly, My table snippit is a database of jobs and the jobs run as a process, so lineal,  The example I have shared is a quote process, So a Job would start at Book, the team member would call to book in the Quote, and that is "Scheduled", Then the Team member attends and it changes to site attended, then the quote is submitted and the status changes again to awaiting insurer.  So I want to be able to report on those statuses, as the metric ber team member assisgned to those jobs.  So on average as a company we take this long to book a quote, and this long to attend, and this long to submit.

 

Does that make sense?

 

So I have a list of users that I set a relationship up with the Record ID, and I want to have performance meetings and say, OK "Team member A" on average this is your job transitions times.

@SamBrown17 Right, it's the same principle but yours will look something like this:

Column = 
  VAR __record = [record_id]
  VAR __type = [event_type]
  VAR __current = [created_at]
  VAR __currentStatus = [To (Status)]
  VAR __previous = 
    IF(__type = "Job status updated",
      SWITCH(__currentStatus,
        "Scheduled",MAXX(FILTER('Table',[record_id] = __record && [From (Status) = "Book" && [To (Status)] = BLANK(),[created_at]),
        "Site Attended",MAXX(FILTER('Table',[record_id] = __record && [From (Status) = "Book" && [To (Status)] = "Scheduled",[created_at])
      )
    )
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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Late to come back but I cannot find out why, but when I try and finished this it results in "The end of the input was reached" and it puts 3 closed brackets on the end every time I hit enter

mh2587
Super User
Super User

VAR CurrentDate = CALCULATE ( MAX(Table[Created_at] ),
ALL( 'Table'[Record_ID] )

)

var LastDate = CALCULATE(
MAX(Table[Created_at]),
ALL( 'Table'[Record_ID] ),

Table[Created_at] < CurrentDate )

VAR DD = DATEDIFF ( LastDate,CurrentDate, DAY )
RETURN DD


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors