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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Syndicate_Admin
Administrator
Administrator

Calculate times between date ranges

The company has commissioned me to analyze the occupancy percentage of a car rental company.
In the contracts table I have a row for each contract and with the data of: start date-time, end date-time and total contract hours.

contract start date end date total hours
255/893 31/12/2022 15:00 02/01/2023 15:00 48
100/236 25/01/2023 9:00 26/01/2023 9:00 24
100/564 07/01/2023 9:00 08/01/2023 8:00 23
100/999 30/01/2023 12:00 01/02/2023 14:30 50,5

A priori, it seems that calculating what the occupancy percentage would be should not be difficult.
The problem occurs when I use a date segmentation in my report.

I have a calendar table that relates to the contract table by the start date.
If in this segmentation framework January 2023 table will be filtered with contracts 100/236, 100/564 and 100/999.
In the case of contract 100/999 I have managed to calculate how many contract hours have been made in January 2023. From 30-01-2023 12:00 to 31-01-23 23:59.

I can then the occupancy percentage with respect to the total hours selected in the segmentation without major problem.

Unfortunately, there is one contract that escapes me. Contract 255/893 has a start date of 31-12-23 so it is outside the filter of segmentation. However, in January 2023, this contract has been in force from 01-01-23 00:00 until 02-01-2023 15:00
In summary, how could you calculate the hours that each contract has been in effect within the segmentation date range regardless of the start or end date of the contract?

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @rsanchezpremium,

According to your description, it seems like a common data range based on multiple date field analysis requirement. You can take a look the Greg’s blog with common situations and refer to the ‘start date’, ‘end date’ parts if it suitable for your requirement.

Before You Post, Read This: start/end date ranges 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Thanks !!, A very interesting blog.

Hi @rsanchezpremium ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
v-shex-msft
Community Support
Community Support

Hi @rsanchezpremium,

According to your description, it seems like a common data range based on multiple date field analysis requirement. You can take a look the Greg’s blog with common situations and refer to the ‘start date’, ‘end date’ parts if it suitable for your requirement.

Before You Post, Read This: start/end date ranges 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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