cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Paradox1023
New Member

Help with calculating specific delay time per day

Hi, I am trying to make a report that would give the delay time per day (which would give me the run time per day to get approximate TPH). An example delay data table is formatted as shown below.  

Paradox1023_0-1685220714950.png

 

Since I have to calculate tons per hour for every day using another table with production information, I created a Calendar table (just a one-column table with only the dates using the CALENDAR() function) that is connected with both the delay table and production table.

 

However, I am struggling to calculate the number of hours of delay time per day with DelayType 0 as a column in the calendar table with the format shown below using the previous delay table as an example. 

Paradox1023_1-1685220048282.png

 

I tried making a calculated column using DATEDIFF() but I am struggling to get only the entries with DelayType of 0 as well as how to deal with delays that span for multiple days (For example, 05/26/2023 falls within the 4th entry of the delay table so the total delay time for that day would be 24 hours).

 

I would appreciate any help or guidance on what I can do to get the final formatted Calendar table. Thank you. 

 

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Paradox1023 ,

 

According to your screenshot, I think you don't need to create a relationship between Calendar Table and Delay Table, due to datetime type column in Delay table and date type column in Calendar.

You can try this code to create a measure.

Total Delay Time due to DelayType 0 (hour) = 
VAR _CROSSJOIN =
    FILTER (
        GENERATE (  ALLSELECTED('Delay Table') , CALCULATETABLE(VALUES ( 'Calendar'[Date] ),ALLSELECTED('Calendar')) ),
        'Delay Table'[DelayType] = 0
            && DATEVALUE ( 'Delay Table'[DelayStartTime] ) <= 'Calendar'[Date]
            && DATEVALUE ( 'Delay Table'[DelayEndTime] ) >= 'Calendar'[Date]
    )
VAR _AddDuartion =
    ADDCOLUMNS (
        _CROSSJOIN,
        "Duration",
            VAR _MIN =
                MINX (
                    FILTER (
                        _CROSSJOIN,
                        AND (
                            'Delay Table'[DelayStartTime] = EARLIER ( 'Delay Table'[DelayStartTime] ),
                            'Delay Table'[DelayEndTime] = EARLIER ( 'Delay Table'[DelayEndTime] )
                        )
                    ),
                    [Date]
                )
            VAR _MAX =
                MAXX (
                    FILTER (
                        _CROSSJOIN,
                        AND (
                            'Delay Table'[DelayStartTime] = EARLIER ( 'Delay Table'[DelayStartTime] ),
                            'Delay Table'[DelayEndTime] = EARLIER ( 'Delay Table'[DelayEndTime] )
                        )
                    ),
                    [Date]
                )
            RETURN
                SWITCH (
                    TRUE (),
                    [Date] = _MIN
                        && [Date] = _MAX, [Duration (hour)],
                    [Date] <> _MIN
                        && [Date] <> _MAX, 24,
                    [Date] = _MIN
                        && [Date] <> _MAX,
                        DATEDIFF ( [DelayStartTime], [Date] + 1, MINUTE ) / 60,
                    [Date] <> _MIN
                        && [Date] = _MAX, DATEDIFF ( [Date], [DelayEndTime], MINUTE ) / 60
                )
    )
RETURN
   SUMX(FILTER(_AddDuartion,[Date] = MAX('Calendar'[Date])),[Duration])+0

Result is as below.

vrzhoumsft_0-1685416755337.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Paradox1023 ,

 

According to your screenshot, I think you don't need to create a relationship between Calendar Table and Delay Table, due to datetime type column in Delay table and date type column in Calendar.

You can try this code to create a measure.

Total Delay Time due to DelayType 0 (hour) = 
VAR _CROSSJOIN =
    FILTER (
        GENERATE (  ALLSELECTED('Delay Table') , CALCULATETABLE(VALUES ( 'Calendar'[Date] ),ALLSELECTED('Calendar')) ),
        'Delay Table'[DelayType] = 0
            && DATEVALUE ( 'Delay Table'[DelayStartTime] ) <= 'Calendar'[Date]
            && DATEVALUE ( 'Delay Table'[DelayEndTime] ) >= 'Calendar'[Date]
    )
VAR _AddDuartion =
    ADDCOLUMNS (
        _CROSSJOIN,
        "Duration",
            VAR _MIN =
                MINX (
                    FILTER (
                        _CROSSJOIN,
                        AND (
                            'Delay Table'[DelayStartTime] = EARLIER ( 'Delay Table'[DelayStartTime] ),
                            'Delay Table'[DelayEndTime] = EARLIER ( 'Delay Table'[DelayEndTime] )
                        )
                    ),
                    [Date]
                )
            VAR _MAX =
                MAXX (
                    FILTER (
                        _CROSSJOIN,
                        AND (
                            'Delay Table'[DelayStartTime] = EARLIER ( 'Delay Table'[DelayStartTime] ),
                            'Delay Table'[DelayEndTime] = EARLIER ( 'Delay Table'[DelayEndTime] )
                        )
                    ),
                    [Date]
                )
            RETURN
                SWITCH (
                    TRUE (),
                    [Date] = _MIN
                        && [Date] = _MAX, [Duration (hour)],
                    [Date] <> _MIN
                        && [Date] <> _MAX, 24,
                    [Date] = _MIN
                        && [Date] <> _MAX,
                        DATEDIFF ( [DelayStartTime], [Date] + 1, MINUTE ) / 60,
                    [Date] <> _MIN
                        && [Date] = _MAX, DATEDIFF ( [Date], [DelayEndTime], MINUTE ) / 60
                )
    )
RETURN
   SUMX(FILTER(_AddDuartion,[Date] = MAX('Calendar'[Date])),[Duration])+0

Result is as below.

vrzhoumsft_0-1685416755337.png

 

Best Regards,
Rico Zhou

 

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

tamerj1
Super User
Super User

Hi @Paradox1023 

please try

Total Delay Time due to DelayType 0 (hour) =
SUMX (
FILTER (
CROSSJOIN ( ALLSELECTED ( 'Delay Table' ), VALUES ( 'Calendar'[Date] ) ),
'Delay Table'[Delay Type] = 0
&& 'Delay Table'[DelayStartTime] <= 'Calendar'[Date]
&& 'Delay Table'[DelayEndTime] >= 'Calendar'[Date]
),
DATEDIFF (
MAX ( 'Delay Table'[DelayStartTime], 'Calendar'[Date] ),
MIN ( 'Delay Table'[DelayEndTime], 'Calendar'[Date] ),
MINUTE
) / 60
)

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors