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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
dading
Helper II
Helper II

Break the duration of status in hourly time frame

Hi..

I'm new user in power bi. Hope someone can help me 😉

 

i have table that contains Status and time start, time end.

From that table i can calculate the duration_hours of each status.

My question is "How can we break the duration in certain time, in this case i want to break it in hourly?"

 

data_source

Timestamp_StartTimestamp_EndDuration_hoursStatus
13/03/2020 7:2813/03/2020 8:30                        1.03A
13/03/2020 8:3013/03/2020 9:15                        0.74B
13/03/2020 9:1513/03/2020 10:37                        1.37A
13/03/2020 10:3713/03/2020 10:50                        0.22C
13/03/2020 10:5013/03/2020 11:05                        0.25B
13/03/2020 11:0513/03/2020 11:28                        0.38C
13/03/2020 11:2813/03/2020 11:50                        0.37A
13/03/2020 11:5013/03/2020 12:10                        0.33B
13/03/2020 12:1013/03/2020 13:10                        1.00

C

 

the result i want is like table below

TimeFrame_StartTimeFrame_EndDuration_hrs_ADuration_hrs_BDuration_hrs_C
13/03/2020 7:0013/03/2020 8:00                        0.52  
13/03/2020 8:0013/03/2020 9:00                        0.51                        0.49 
13/03/2020 9:0013/03/2020 10:00                        0.75                        0.25 
13/03/2020 10:0013/03/2020 11:00                        0.62                        0.17          0.22
13/03/2020 11:0013/03/2020 12:00                        0.37                        0.25          0.38
13/03/2020 12:0013/03/2020 13:00                         0.17          0.83
13/03/2020 13:0013/03/2020 14:00            0.17

 

the total duration should be same 5.69 hours

 

thanks in advance

 

1 ACCEPTED SOLUTION

Hi @dading 

Create a new query in edit queries,

Capture8.JPG

Close&&apply, create measures

Capture7.JPG

hours_A =
VAR value_a =
    CALCULATE (
        SUM ( 'Table'[Duration_hours] ),
        FILTER (
            'Table',
            'Table'[Timestamp_Start]
                <= MAX ( 'Datetime list'[DateTime2] )
                && 'Table'[Timestamp_End]
                    >= MAX ( 'Datetime list'[DateTime] )
                && 'Table'[Status] = "A"
        )
    )
VAR mins =
    CALCULATE (
        MIN ( 'Table'[Timestamp_Start] ),
        FILTER (
            'Table',
            'Table'[Timestamp_Start]
                <= MAX ( 'Datetime list'[DateTime2] )
                && 'Table'[Timestamp_End]
                    >= MAX ( 'Datetime list'[DateTime] )
                && 'Table'[Status] = "A"
        )
    )
VAR maxe =
    CALCULATE (
        MAX ( 'Table'[Timestamp_End] ),
        FILTER (
            'Table',
            'Table'[Timestamp_Start]
                <= MAX ( 'Datetime list'[DateTime2] )
                && 'Table'[Timestamp_End]
                    >= MAX ( 'Datetime list'[DateTime] )
                && 'Table'[Status] = "A"
        )
    )
VAR h =
    IF (
        MAX ( 'Datetime list'[DateTime] ) <= mins,
        IF (
            MAX ( 'Datetime list'[DateTime2] ) <= maxe,
            DATEDIFF (
                mins,
                MAX ( 'Datetime list'[DateTime2] ),
                MINUTE
            ),
            DATEDIFF (
                mins,
                maxe,
                MINUTE
            )
        ),
        DATEDIFF (
            MAX ( 'Datetime list'[DateTime] ),
            maxe,
            MINUTE
        )
    )
VAR p =
    h
        / DATEDIFF (
            mins,
            maxe,
            MINUTE
        )
RETURN
    p * value_a

For [hours_b] and [hours_c] change the "A" in the measure above to "B" or "C".

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

Are you trying to do something like Hour Breakdown? https://community.powerbi.com/t5/Quick-Measures-Gallery/Hour-Breakdown/m-p/625085#M306

 

Sorry, not 100% clear.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

yup..thats it

but i want the result until second level,

so which part should i modify? 

 

v-juanli-msft
Community Support
Community Support

Hi @dading 

It seems your hours are divided by the time intervals.

But i can't detemine how to spilt the hours, could you help to define the rule?

 

Best Regards

Maggie

 

sure..

i save the excel file in google drive

link 

can you open it? @v-juanli-msft 

 

Hi @dading 

Create a new query in edit queries,

Capture8.JPG

Close&&apply, create measures

Capture7.JPG

hours_A =
VAR value_a =
    CALCULATE (
        SUM ( 'Table'[Duration_hours] ),
        FILTER (
            'Table',
            'Table'[Timestamp_Start]
                <= MAX ( 'Datetime list'[DateTime2] )
                && 'Table'[Timestamp_End]
                    >= MAX ( 'Datetime list'[DateTime] )
                && 'Table'[Status] = "A"
        )
    )
VAR mins =
    CALCULATE (
        MIN ( 'Table'[Timestamp_Start] ),
        FILTER (
            'Table',
            'Table'[Timestamp_Start]
                <= MAX ( 'Datetime list'[DateTime2] )
                && 'Table'[Timestamp_End]
                    >= MAX ( 'Datetime list'[DateTime] )
                && 'Table'[Status] = "A"
        )
    )
VAR maxe =
    CALCULATE (
        MAX ( 'Table'[Timestamp_End] ),
        FILTER (
            'Table',
            'Table'[Timestamp_Start]
                <= MAX ( 'Datetime list'[DateTime2] )
                && 'Table'[Timestamp_End]
                    >= MAX ( 'Datetime list'[DateTime] )
                && 'Table'[Status] = "A"
        )
    )
VAR h =
    IF (
        MAX ( 'Datetime list'[DateTime] ) <= mins,
        IF (
            MAX ( 'Datetime list'[DateTime2] ) <= maxe,
            DATEDIFF (
                mins,
                MAX ( 'Datetime list'[DateTime2] ),
                MINUTE
            ),
            DATEDIFF (
                mins,
                maxe,
                MINUTE
            )
        ),
        DATEDIFF (
            MAX ( 'Datetime list'[DateTime] ),
            maxe,
            MINUTE
        )
    )
VAR p =
    h
        / DATEDIFF (
            mins,
            maxe,
            MINUTE
        )
RETURN
    p * value_a

For [hours_b] and [hours_c] change the "A" in the measure above to "B" or "C".

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors