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
hackfifi
Helper V
Helper V

Calculate Duration between Milestones

Hello Good Day

I have the below TABLE with 3 Columns --> Project, Activity & Date.

 

Query 1: Calculate the duration for each activity from Milestone 1 per Project. See RESULT Column

Query 2: I will need to work out a way for a user to select two different milestones from probably 2 x Drop Down Lists i.e. Select Milestone Option 1 & Milestone Option 2 -  but it should calculate the duration between those milestones. 

 

Cheers!!

 

 

Milestone Query.PNG

2 ACCEPTED SOLUTIONS
v-frfei-msft
Community Support
Community Support

Hi @hackfifi ,

 

Here I create one sample for your reference.

 

Q1: To create a calculated column as below.

 

Column = 
VAR M1date =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER ( ALLEXCEPT ( Table1, Table1[Project] ), Table1[activity] = "M1" )
    )
RETURN
    DATEDIFF ( M1date, 'Table1'[Date], DAY )

Q2:

 

1. Create two calculated table.

 

between1 = DISTINCT(Table1[activity])
between2 = DISTINCT(Table1[activity])

2. Create a meausre to get the reuslt we need.

 

Measure = 
VAR startdate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Project] ),
            Table1[activity] = SELECTEDVALUE ( between1[From] )
        )
    )
VAR todate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Project] ),
            Table1[activity] = SELECTEDVALUE ( between2[To] )
        )
    )
RETURN
    DATEDIFF ( startdate, todate, DAY )

Capture.PNG

For more details, please check the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

Hi @hackfifi ,

 

To use a new measure to work on it.

 

Measure 2 =
VAR startdate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Project] = SELECTEDVALUE ( Projects[Project] )
                && Table1[activity] = SELECTEDVALUE ( between1[From] )
        )
    )
VAR todate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Project] = SELECTEDVALUE ( Projects[Project] )
                && Table1[activity] = SELECTEDVALUE ( between2[To] )
        )
    )
RETURN
    DATEDIFF ( startdate, todate, DAY )

2.PNG

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

7 REPLIES 7
v-frfei-msft
Community Support
Community Support

Hi @hackfifi ,

 

Here I create one sample for your reference.

 

Q1: To create a calculated column as below.

 

Column = 
VAR M1date =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER ( ALLEXCEPT ( Table1, Table1[Project] ), Table1[activity] = "M1" )
    )
RETURN
    DATEDIFF ( M1date, 'Table1'[Date], DAY )

Q2:

 

1. Create two calculated table.

 

between1 = DISTINCT(Table1[activity])
between2 = DISTINCT(Table1[activity])

2. Create a meausre to get the reuslt we need.

 

Measure = 
VAR startdate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Project] ),
            Table1[activity] = SELECTEDVALUE ( between1[From] )
        )
    )
VAR todate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Project] ),
            Table1[activity] = SELECTEDVALUE ( between2[To] )
        )
    )
RETURN
    DATEDIFF ( startdate, todate, DAY )

Capture.PNG

For more details, please check the pbix as attached.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

 

@v-frfei-msft - another query.

so i actually have a MASTER "Project" table. In this case a table "Project" with a,b,c

but even if i create a relationship between Table "Project" & Table1, the filter do not seem to work. Any workaround for this?
i would attach the below PBIX file, but i am not exactly sure how to!

Filter Query.PNG

@v-frfei-msft  - Frank: Did you have a chance to look into this?

Hi @hackfifi ,

 

Please upload your files to OneDrive and share the link here.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi Frank - Let me know if this works?

 

https://1drv.ms/u/s!Ahwb9FOvNbslhgWsRicFhh6pAa0Q

 

Hi @hackfifi ,

 

To use a new measure to work on it.

 

Measure 2 =
VAR startdate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Project] = SELECTEDVALUE ( Projects[Project] )
                && Table1[activity] = SELECTEDVALUE ( between1[From] )
        )
    )
VAR todate =
    CALCULATE (
        MAX ( 'Table1'[Date] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Project] = SELECTEDVALUE ( Projects[Project] )
                && Table1[activity] = SELECTEDVALUE ( between2[To] )
        )
    )
RETURN
    DATEDIFF ( startdate, todate, DAY )

2.PNG

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks Mate @v-frfei-msft  - Works like a charm!

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.