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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculating Duration between two or more dates in one column based on a condition

I know this type of question has been asked repeatedly and I have spent hours trying to apply it to my situation but have failed so far. 

Here is what the data model looks like.  There are multiple different type of fields and new values but the ones in the example are what I am concerned about. 

--Program Parent ID----History   ID----New Value-----Field--Date--
123346CreatedImplementation Status6/1/2020
123789KickoffImplementation Status6/3/2020
123101HandoffImplementation Status6/7/2020

 

In the past the data model would look like this and it would be simple datediff calcs:

-Program Parent ID---Created Date--Kickoff Date--Handoff Date-
1236/1/20206/3/20206/7/2020

 

Ultimately for every Program (Parent ID) I want to calculate duration from created to kickoff, or kickoff to handoff or created to handoff for example. This is what I have tried https://www.youtube.com/watch?v=jYvr4histgY  but her calc wasn't working for me. 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Here's a measure for one of the questions, it also illustrates the general approach

 

C to K = 
var p=SELECTEDVALUE('Table'[--Program Parent ID--])
var c=CALCULATE(max('Table'[--Date--]),all('Table'),'Table'[--Program Parent ID--]=p,'Table'[--New Value--]="Created")
var k=CALCULATE(max('Table'[--Date--]),all('Table'),'Table'[--Program Parent ID--]=p,'Table'[--New Value--]="Kickoff")
var h=CALCULATE(max('Table'[--Date--]),all('Table'),'Table'[--Program Parent ID--]=p,'Table'[--New Value--]="Handoff")
return datediff(c,k,DAY)

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Here's a measure for one of the questions, it also illustrates the general approach

 

C to K = 
var p=SELECTEDVALUE('Table'[--Program Parent ID--])
var c=CALCULATE(max('Table'[--Date--]),all('Table'),'Table'[--Program Parent ID--]=p,'Table'[--New Value--]="Created")
var k=CALCULATE(max('Table'[--Date--]),all('Table'),'Table'[--Program Parent ID--]=p,'Table'[--New Value--]="Kickoff")
var h=CALCULATE(max('Table'[--Date--]),all('Table'),'Table'[--Program Parent ID--]=p,'Table'[--New Value--]="Handoff")
return datediff(c,k,DAY)

Hi @Anonymous 

Have you tried this formula:

 

Kickoff to Created =

VAR kickoff =
CALCULATE
(
   MAX(table[Date]),
   FILTER
   (
      ALLEXCEPT(table, table[Program Parent ID]),
      table[New Value] = "Kickoff"
   )
)

VAR created =
CALCULATE
(
   MAX(table[Date]),
   FILTER
   (
      ALLEXCEPT(table, table[Program Parent ID]),
      table[New Value] = "Created"
   )
)

RETURN
DATEDIFF(kickoff, created, DAY)

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors