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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Puja
Helper III
Helper III

Duration Calculation

Hello Community,

I need some help to calculate the duration based on an event.

Based on those highlighted (screenshot below) dates , I need to calculate the duration.

Anytime , 9999  or 7777  events occurs , duration should be calculed with next immidiate event datetime which is always 55.

TIA

Puja_1-1658366393202.png

 

Sample data

Product nameDateTimeEventResult
Product 17/19/2022 6:38:25 PM8 
Product 17/19/2022 6:47:20 PM55 
Product 17/19/2022 7:29:31 PM55 
Product 17/19/2022 8:17:36 PM55 
Product 17/19/2022 8:30:29 PM999923 min 24 sec
Product 17/19/2022 8:53:53 PM55 
Product 17/19/2022 9:00:21 PM55 
Product 17/19/2022 9:16:29 PM55 
Product 17/19/2022 9:25:21 PM55 
Product 17/19/2022 9:32:16 PM55 
Product 17/19/2022 9:47:20 PM7777 
Product 17/19/2022 10:32:48 PM55 
Product 17/19/2022 10:45:27 PM55 
Product 17/19/2022 10:53:31 PM55 
Product 17/19/2022 11:15:18 PM55 
Product 17/19/2022 11:33:29 PM55 
Product 17/19/2022 11:45:45 PM55 

 

 

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below, and it is for creating a new column.

 

Untitled.png

 

Result seconds CC =
VAR _tableperproductnextdatetime =
    FILTER (
        ADDCOLUMNS (
            ADDCOLUMNS (
                Data,
                "@nextdatetime",
                    MINX (
                        FILTER (
                            Data,
                            Data[Product name] = EARLIER ( Data[Product name] )
                                && Data[DateTime] > EARLIER ( Data[DateTime] )
                        ),
                        Data[DateTime]
                    )
            ),
            "@diff", DATEDIFF ( Data[DateTime], [@nextdatetime], SECOND )
        ),
        Data[Event] IN { 9999, 7777 }
    )
RETURN
    SUMMARIZE (
        FILTER (
            _tableperproductnextdatetime,
            Data[Product name] = EARLIER ( Data[Product name] )
                && Data[Event] = EARLIER ( Data[Event] )
        ),
        [@diff]
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

Hi,

Please share your sample pbix file's link, and then I can try to look into it to come up with a solution.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below, and it is for creating a new column.

 

Untitled.png

 

Result seconds CC =
VAR _tableperproductnextdatetime =
    FILTER (
        ADDCOLUMNS (
            ADDCOLUMNS (
                Data,
                "@nextdatetime",
                    MINX (
                        FILTER (
                            Data,
                            Data[Product name] = EARLIER ( Data[Product name] )
                                && Data[DateTime] > EARLIER ( Data[DateTime] )
                        ),
                        Data[DateTime]
                    )
            ),
            "@diff", DATEDIFF ( Data[DateTime], [@nextdatetime], SECOND )
        ),
        Data[Event] IN { 9999, 7777 }
    )
RETURN
    SUMMARIZE (
        FILTER (
            _tableperproductnextdatetime,
            Data[Product name] = EARLIER ( Data[Product name] )
                && Data[Event] = EARLIER ( Data[Event] )
        ),
        [@diff]
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim , Thanks for your help .
I see this error . Any thoughts ?

Puja_0-1658955664421.png

 

Hi,

Please share your sample pbix file's link, and then I can try to look into it to come up with a solution.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you @Jihwan_Kim . Its working as expected :).

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.