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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
DreDre
Helper II
Helper II

Line chart counting duration based on a start/End time

Long story short, I have start/end times in different rows and I am trying to create a line chart that gives a total number of people that fall between these two points so that I know how many people are working.

 

For example:

PersonStartEnd

1

08:0016:30
208:0516:35
312:0020:30
414:3022:00
515:0023:30
616:0000:30

If I were to look at 12:00, I should have 3 people working, then at 15:00 I would have 5 and finally at 18:00 I should have 4. My goal is to be able to look at every minute of the day and see how many people are working based on the Start/End columns in a table. Any help or guidance would be very helpful!

1 ACCEPTED SOLUTION
DataZoe
Microsoft Employee
Microsoft Employee

@DreDre 

 

Is this what you are going for:

 

active workers.JPG

 

 

 

 

For this I would create a calculated table giving me each minute of the day:

 

TimeTable =
VAR HourTable =
    SELECTCOLUMNS ( GENERATESERIES ( ( 0 ), ( 23 ) ), "Hour", [Value] )
VAR MinuteTable =
    SELECTCOLUMNS ( GENERATESERIES ( ( 0 ), ( 59 ) ), "Minute", [Value] )
RETURN
    ADDCOLUMNS (
        CROSSJOIN ( HourTable, MinuteTable ),
        "Time", TIME ( [Hour], [Minute], 0 )
    )

 

(modified from here: https://kohera.be/blog/power-bi/how-to-create-a-time-table-in-power-bi-in-a-few-simple-steps/ )

 

That would be the x-axis and I wouldn't create a relationship to this table!

 

I would then create a measure to count how many people are working at each time, like this:

 

Active Workers =
CALCULATE (
    DISTINCTCOUNT ( Hours[Person] ),
    FILTER (
        Hours,
        Hours[Start] <= MIN ( TimeTable[Time] )
            && Hours[End] > MAX ( TimeTable[Time] )
    )
)

 

 

and then put it on the line chart.

 

Edit: Also make sure all the time fields are in the "Time" datetype.

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

5 REPLIES 5
DataZoe
Microsoft Employee
Microsoft Employee

@DreDre 

 

Is this what you are going for:

 

active workers.JPG

 

 

 

 

For this I would create a calculated table giving me each minute of the day:

 

TimeTable =
VAR HourTable =
    SELECTCOLUMNS ( GENERATESERIES ( ( 0 ), ( 23 ) ), "Hour", [Value] )
VAR MinuteTable =
    SELECTCOLUMNS ( GENERATESERIES ( ( 0 ), ( 59 ) ), "Minute", [Value] )
RETURN
    ADDCOLUMNS (
        CROSSJOIN ( HourTable, MinuteTable ),
        "Time", TIME ( [Hour], [Minute], 0 )
    )

 

(modified from here: https://kohera.be/blog/power-bi/how-to-create-a-time-table-in-power-bi-in-a-few-simple-steps/ )

 

That would be the x-axis and I wouldn't create a relationship to this table!

 

I would then create a measure to count how many people are working at each time, like this:

 

Active Workers =
CALCULATE (
    DISTINCTCOUNT ( Hours[Person] ),
    FILTER (
        Hours,
        Hours[Start] <= MIN ( TimeTable[Time] )
            && Hours[End] > MAX ( TimeTable[Time] )
    )
)

 

 

and then put it on the line chart.

 

Edit: Also make sure all the time fields are in the "Time" datetype.

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

I am working on trying to adapt this for my dataset, but yes, your image is exactly what I am trying to accomplish! Thank-you so much @DataZoe for the help! This one has been bothering me.

DataZoe
Microsoft Employee
Microsoft Employee

@DreDre here is the pbix too: https://github.com/DataZoe/PBIX/blob/master/Active%20Hourly%20Workers.pbix The only data structure change I could see was the worker who went to 12:30AM, may need to have 2 entries, one until 11:50pm then a second one from 12:00am to 12:30am, or something like that.

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

amitchandak
Super User
Super User

@DreDre , very similar to this blog. refer if this can help.

 

An hourly bucket Table will act as a date table

 

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

This is not quite what I was trying to accomplish as I am trying to do time throughout a day vs dates.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors