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
metcala
Helper III
Helper III

Total days in status

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 have received a partial solution however this was limited with a switch statement requiring hardcoded project IDs.

 

Thanks!

1 ACCEPTED SOLUTION
ERD
Super User
Super User

Hi @metcala, you can try the measure below:

daysAmt = 
var _t = 
    ADDCOLUMNS (
        FILTER (
            SUMMARIZE (
                Task,
                Customer[Customer],
                Project[Project ID],
                Project[End Date],
                Task[Task Type],
                Task[Start Date],
                Task[End Date]
            ),
            Project[End Date] = BLANK ()
        ),
        "_days",
            VAR _customer = CALCULATE ( MAX ( Customer[Customer] ) )
            VAR _taskType = CALCULATE ( MAX ( Task[Task Type] ) )
            VAR _checkIfBlank =
                CALCULATE (
                    COUNT ( Task[Task Type] ),
                    Customer[Customer] = _customer,
                    Task[End Date] = BLANK (),
                    Task[Task Type] = _taskType,
                    REMOVEFILTERS ()
                )
            VAR _maxDate =
                CALCULATE (
                    MAX ( Task[End Date] ),
                    Customer[Customer] = _customer,
                    Task[Task Type] = _taskType,
                    ALL ( Task[End Date] )
                )
            VAR _minDate =
                CALCULATE (
                    MIN ( Task[Start Date] ),
                    Customer[Customer] = _customer,
                    Task[Task Type] = _taskType,
                    ALL ( Task[Start Date] )
                )
            RETURN
                IF (
                    _checkIfBlank > 0,
                    DATEDIFF ( _minDate, TODAY (), DAY ),
                    DATEDIFF ( _minDate, _maxDate, DAY )
                )
    )
RETURN
    MAXX ( _t, [_days] )

ERD_0-1701285103238.png

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

2 REPLIES 2
metcala
Helper III
Helper III

@ERD  Thanks so much, that worked perfectly!

ERD
Super User
Super User

Hi @metcala, you can try the measure below:

daysAmt = 
var _t = 
    ADDCOLUMNS (
        FILTER (
            SUMMARIZE (
                Task,
                Customer[Customer],
                Project[Project ID],
                Project[End Date],
                Task[Task Type],
                Task[Start Date],
                Task[End Date]
            ),
            Project[End Date] = BLANK ()
        ),
        "_days",
            VAR _customer = CALCULATE ( MAX ( Customer[Customer] ) )
            VAR _taskType = CALCULATE ( MAX ( Task[Task Type] ) )
            VAR _checkIfBlank =
                CALCULATE (
                    COUNT ( Task[Task Type] ),
                    Customer[Customer] = _customer,
                    Task[End Date] = BLANK (),
                    Task[Task Type] = _taskType,
                    REMOVEFILTERS ()
                )
            VAR _maxDate =
                CALCULATE (
                    MAX ( Task[End Date] ),
                    Customer[Customer] = _customer,
                    Task[Task Type] = _taskType,
                    ALL ( Task[End Date] )
                )
            VAR _minDate =
                CALCULATE (
                    MIN ( Task[Start Date] ),
                    Customer[Customer] = _customer,
                    Task[Task Type] = _taskType,
                    ALL ( Task[Start Date] )
                )
            RETURN
                IF (
                    _checkIfBlank > 0,
                    DATEDIFF ( _minDate, TODAY (), DAY ),
                    DATEDIFF ( _minDate, _maxDate, DAY )
                )
    )
RETURN
    MAXX ( _t, [_days] )

ERD_0-1701285103238.png

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

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.