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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
metcala
Helper III
Helper III

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 2
Anonymous
Not applicable

Hi @metcala ,

Below is my table1:

vxiandatmsft_0-1700796444221.png

Below is my table2:

vxiandatmsft_1-1700796466788.png

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:

vxiandatmsft_2-1700796618479.png

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.

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.