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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
aakunkle
Microsoft Employee
Microsoft Employee

Get Time Encapsulated by Date Ranges

I've got a table with a bunch of rows with columns for MachineID(int), StartTime(DateTime), and EndTime(DateTime).  I want to get the total amount of time falling inside at least one of the time ranges for each entry, for a given MachineID.

 

Is there a way to create a Measure (mapping to MachineID) that does this?  I can think of a way to do this with code, but searching through DAX functions doesn't seem to be returning anything useful.

1 ACCEPTED SOLUTION

Hi,

If you include the beginning and ending dates, the results should be 59 and 21.  You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

So for

MachineID   StartTime                 EndTime                     
11/3/2021 0:00:001/9/2021 0:00:00
11/3/2021 0:00:001/15/2021 0:00:00
13/4/2021 0:00:003/11/2021 0:00:00
13/6/2021 0:00:003/7/2021 0:00:00
13/10/2021 0:00:004/18/2021 0:00:00
21/3/2021 0:00:001/7/2021 0:00:00
22/5/2021 0:00:00 2/20/2021 0:00:00

 

the output would be

 

MachineID  TimeEncapsulated(days)
157
219

 

How did you arrive at 57 and 19?  Explain.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

The 57 comes from the total days covered by the date ranges covering 1/3 to 1/15 and 3/4 to 4/18 for machine 1.  The 19 comes from total days covered by the two non-overlapping date ranges for machine 2.

Hi,

If you include the beginning and ending dates, the results should be 59 and 21.  You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Your PBI file doesn't indicate how "Date" was generated from "StartTime" and "EndTime".  Did you generate a new table by adding an entry for every day that fell within the range for a given machine ID, or something else?

Hi,

Please study the steps in the Query Editor.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.