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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Cro-Magnon
Regular Visitor

Correct total amount of time for date ranges that can potentially overlap (even if partially)

The table I have has the date range for which an equipment has been installed on a certain location.

 

Let's assume just 2 equipment and one location, and let's ignore months and days, for simplicity:

EQ_IDLOC_IDDATE_FROMDATE_TO
112000-01-012002-01-01
212005-01-012010-01-01
112008-01-012012-01-01

 

I'm trying to determine for each location the total amount of time it has had equipment installed.
The problem is that multiple equipment can be installed at a certain location at any given time, but shall not be counted multiple times.

In the example above, Location 1 has had equipment installed a total of 9 years: 2 years from 2000 to 2002, and then 7 years from 2005 to 2012 (since the date ranges 2005 to 2010, and 2008 to 2012 partially overlap).

 

What is the best way to accomplish this in Power BI?

1 ACCEPTED SOLUTION
Deku
Super User
Super User

Added a date table to help with the calculation

dates = 
CALENDAR( min( 'Table'[DATE_FROM] ) , MAX( 'Table'[DATE_TO] ) )

Deku_0-1741952904192.png

 

daysPerLoc = 
var days = 
	GENERATE(
	VALUES( 'Table' )
	,DATESBETWEEN( dates[Date], 'Table'[DATE_FROM], 'Table'[DATE_TO] )
	) 
var distinctDayPerLocation =
	COUNTROWS( SUMMARIZE( days, 'Table'[LOC_ID], dates[Date] ) )
RETURN distinctDayPerLocation

 

yearsPerLocation = [daysPerLoc] / 365

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

You can create a measure to return the total number of days like

Total days installed =
VAR InstalledDates =
    SELECTCOLUMNS (
        GENERATE ( 'Table', CALENDAR ( 'Table'[Date_from], 'Table'[Date_to] ) ),
        [Date]
    )
VAR Result =
    COUNTROWS ( DISTINCT ( InstalledDates ) )
RETURN
    Result
Deku
Super User
Super User

Added a date table to help with the calculation

dates = 
CALENDAR( min( 'Table'[DATE_FROM] ) , MAX( 'Table'[DATE_TO] ) )

Deku_0-1741952904192.png

 

daysPerLoc = 
var days = 
	GENERATE(
	VALUES( 'Table' )
	,DATESBETWEEN( dates[Date], 'Table'[DATE_FROM], 'Table'[DATE_TO] )
	) 
var distinctDayPerLocation =
	COUNTROWS( SUMMARIZE( days, 'Table'[LOC_ID], dates[Date] ) )
RETURN distinctDayPerLocation

 

yearsPerLocation = [daysPerLoc] / 365

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
bhanu_gautam
Super User
Super User

@Cro-Magnon 

Create a new table to hold the unique date ranges for each location. You can do this by creating a calculated table in Power BI.

UniqueDateRanges =
VAR DateRanges =
ADDCOLUMNS(
EquipmentInstallations,
"DateFrom", [DATE_FROM],
"DateTo", [DATE_TO]
)
VAR ExpandedRanges =
GENERATE(
DateRanges,
SELECTCOLUMNS(
CALENDAR([DateFrom], [DateTo]),
"Date", [Date]
)
)
RETURN
DISTINCT(ExpandedRanges)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.