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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Ana_Cardoso
Frequent Visitor

Getting duration of a cleaning procedure - DAX

Hey Guys me and @mayara_tavares

have a dashboard to monitoring cleaning procedure andwe execute this procedure Serveral times during the day. So we Have to calculate the duration in each of the procedures. Here an example of the data.

 

When the value is 14 the procedure is runing and when the value goes to 30 or 31 the procedure are done.

 

Time stamping Value
27/06/2020 05:40 0,00
27/06/2020 05:40 0,00
27/06/2020 05:41 14,00
27/06/2020 05:43 14,00
27/06/2020 05:43 14,00
27/06/2020 05:43 14,00
27/06/2020 05:45 14,00
27/06/2020 06:14 14,00
27/06/2020 06:17 14,00
27/06/2020 06:17 14,00
27/06/2020 06:17 30,00
27/06/2020 06:17 0,00
27/06/2020 06:21 12,00
27/06/2020 06:24 12,00
27/06/2020 06:24 12,00
27/06/2020 06:24 12,00
27/06/2020 06:25 14,00
27/06/2020 06:26 14,00
27/06/2020 06:26 14,00
27/06/2020 06:26 14,00
27/06/2020 06:53 14,00
27/06/2020 06:55 14,00
27/06/2020 06:55 14,00
27/06/2020 06:57 31,00
27/06/2020 06:57 0,00

 

So, in this case we should have two procedures and the durantion of each one of them.

 

number of occurencyDuration (minutes)
136
232

 

Could someone help us with a DAX measure to calculate this duration?

 

Just for note: we are using direct query I can only use DAX for it

3 REPLIES 3
MFelix
Super User
Super User

Hi @Ana_Cardoso  and @mayara_tavares ,

 

You can create the following measure:

 

Duration =
VAR StartTime =
    MINX ( FILTER ( 'Table', 'Table'[Value] = 14 ), 'Table'[Time stamping] )
VAR EndTime =
    MAXX (
        FILTER ( 'Table', 'Table'[Value] IN { 30; 31 } ),
        'Table'[Time stamping]
    )
RETURN
    DATEDIFF ( StartTime, EndTime, MINUTE )

 

I'm assuming you have an ID column for the ocurrency number if not you need to have one, tell me if you need any assistance on making it.

 

Check PBIX file attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



hi @MFelix Thank for you help! We don't have an ID column.

 

How We can create this in a DAX? because we can create a new column because our data is directquery

 

Thank you!

Hi @mayara_tavares ,

 

Do you have any other fields that you use on your table to know that is changing from one job to the other or is it just when the 0 value appears on the table?

 

On your example you start at 5:40AM and the go until 6:17AM and a new one starts is there any column or columns that you reference as if it was an ID column?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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