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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
gedal
Frequent Visitor

Calculate the time an object is active within time interval selected

Hi
I'm looking to calculate the time that a given object is active within a chosen timespan on the date dimension. I've tried to illustrate this in the picture here:

gedal_0-1686667593349.png

picture example: in this example the measure should return, that the object has been active for 15 days. 

data:

object idstatusstart timeend time
1active25/03/202305/04/2023
1down05/04/202315/04/2023
1active15/04/202325/04/2023
1down25/04/202305/05/2023


Result wanted:

object idactive days
115


data model:

gedal_2-1686668489026.png

model explanation: the calendar dimension is connected to the fact with 2 inactive connecters. one to the start date and one to the end date. 


First i tried just calculating the time difference on between the dates in a new column on the fact, and wrote this calculation:

CALCULATE(
    SUM(FACT[Duration (ms)]),
    KEEPFILTERS(FACT[Status] = 'active'),
    FILTER('FACT',
        'FACT'[Date Start] >= MIN(calendar[Date])
        && 'FACT'[Date End]  <= MAX(calendar[Date])
    )

but this will not give the correct output. since it returns 0 if the start or end dates are not within the calendar selection. Also it will return the full amount of time (10 days) for the first active event in the picture above and not 5 days as needed. 

Does anyone have an idea of how to handle this request?


5 REPLIES 5
lbendlin
Super User
Super User

Your End Time and Start Time values overlap. That will not work / lead to duplication. You need better granularity.

thanks for reply 🙂
I'm not sure i see the same issue. Because i filter on status = active, so they will never overlap. Is there something in the background of PBI that I'm not aware of?
also what i'm trying to achive is basically an "event in progress calculation" but instead of counting events i want to sum the time. 

On 5/4/2023 was your Object 1 active or was it down?

the object is active, then down, then active then down. 
So  I wanna see: for how long was my object active within the timespan chosen on the calendar filter. The timespan selected is 30 days, and the object was active for 15 of those days. 

It was also down for 17 days in the same period. 15 + 17 = 30 ??

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.