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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! 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 Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors