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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
aakunkle
Employee
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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