Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Calculating days in status for active projects

Hi

 

Any help with this would be much appreciated!

 

I have the following tables:

 

Customer Table

CustomerProject ID
A1001
B1002
C1003
C1004

 

Project Table

Project IDTypeStart DateEnd Date
1001Full1/1/202331/10/2023
1002Full1/1/2023 
1003Full1/4/202330/6/2023
1004Partial1/7/2023 

 

Task Table

Task IDProject IDTask TypeStart DateEnd Date
1111111001A1/1/202331/3/2023
1111121001B1/4/202330/6/2023
1111131001C1/7/202331/10/2023
1111141002A1/1/202331/3/2023 
1111151002A1/1/202330/6/2023
1111161002B1/7/2023 
1111171003A1/4/202330/4/2023
1111181003B1/5/202331/5/2023
1111191003C1/6/202330/6/2023
1111201004A1/7/2023 

 

Task Requests

Project IDTask ATask BTask C
1001111
1002211
1003111
1004111

 

I am looking to show for any active projects (i.e. no project end date) how long each stage has taken. There may be multiple of the same task required (outlined on task requests table). If all tasks haven't been completed it should be the difference between when the first of that task type was started and today, if all tasks have been completed it should be the difference between when the first of that task type was started and the date the final task of that type was completed.

 

The table below shows the expected outcome:

 

CustomerTask A (days)Task B (days)Task C (days)
B180 (30/6* - 1/1)145 (Today - 1/7) 
C145 (Today - 1/7)  

 

*latest date for task type A to be completed

 

I was thinking of creating a calculated column for each stage but any guidance would be much appreciated.

 

Thanks!

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Below is my table1:

    Below is my table2:

    The following DAX might work for you:

    task A = 
        var a = 'Task Table'[End Date] - 'Task Table'[Start Date]
        var b = NOW() - 'Task Table'[Start Date]
        var result1 = IF('Task Table'[End Date]<>0&&'Task Table'[Task Type] = "A" ,a,b)
        var result = 
            SWITCH(
                TRUE(),
                'Task Table'[Project ID] = 1001 && 'Task Table'[Task Type] = "A" , result1,
                'Task Table'[Project ID] = 1002  && 'Task Table'[Task Type] = "A"  , result1,
                'Task Table'[Project ID] = 1003  && 'Task Table'[Task Type] = "A" , result1,
                'Task Table'[Project ID] = 1004  && 'Task Table'[Task Type] = "A" , result1
            )
        return result
    task B = 
        var a = 'Task Table'[End Date] - 'Task Table'[Start Date]
        var b = NOW() - 'Task Table'[Start Date]
        var result1 = IF('Task Table'[End Date]<>0&&'Task Table'[Task Type] = "B" ,a,b)
        var result = 
            SWITCH(
                TRUE(),
                'Task Table'[Project ID] = 1001  &&'Task Table'[Task Type] = "B", result1,
                'Task Table'[Project ID] = 1002 &&'Task Table'[Task Type] = "B" , result1,
                'Task Table'[Project ID] = 1003 &&'Task Table'[Task Type] = "B", result1
            )
        return result
    task C = 
        var a = 'Task Table'[End Date] - 'Task Table'[Start Date]
        var b = NOW() - 'Task Table'[Start Date]
        var result1 = IF('Task Table'[End Date]<>0&&'Task Table'[Task Type] = "C" ,a,b)
        var result = 
            SWITCH(
                TRUE(),
                'Task Table'[Project ID] = 1001 &&'Task Table'[Task Type] = "C" , result1,
                'Task Table'[Project ID] = 1002 &&'Task Table'[Task Type] = "C" , result1,
                'Task Table'[Project ID] = 1003 &&'Task Table'[Task Type] = "C" , result1
            )
        return result

    create a measure:

    task A = 
       CALCULATE(
        MAX('Task Table'[task A]),
        FILTER('Customer Table','Customer Table'[Customer] = "B" || 'Customer Table'[Customer] = "C")
       )
    task B = 
       CALCULATE(
        MAX('Task Table'[task B]),
        FILTER('Customer Table','Customer Table'[Customer] = "B" || 'Customer Table'[Customer] = "C")
       )
    task C = 
       CALCULATE(
        MAX('Task Table'[task C]),
        FILTER('Customer Table','Customer Table'[Customer] = "B" || 'Customer Table'[Customer] = "C")
       )

    The final output is shown in the following figure:

    Best Regards,

    Xianda Tang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi

       

      Thank you very much for the response.

       

      Is there anyway that the switch statement could be dynamic i.e. from Project 1001 to XXXX. I have only included projects 1001-1004 as a representation of the dataset there are in fact a few hundred?

       

      Thanks again