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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
PowerBigginer
Helper II
Helper II

Dax help on to calculate login logout min in each hour interval

Hi Team,
I want to calculate difference in minutes for each one hour. 

If an employee logs in at 8:30 and logs out at 11:30, we want to calculate the time spent for each hourly interval. Here's how it should look:

For the 8-9 interval: 30 minutes
For the 9-10 interval: 60 minutes
For the 10-11 interval: 60 minutes
For the 11-12 interval: 30 minutes (because the logout time is at 11:30)


Sample data

Emp IdEmp NameJob TitleLog In TimeLog Out TimeDif in minHourlyInterval
123HariManager5/2/2024 8:255/2/2024 11:0015508-09
123HariManager5/2/2024 8:205/2/2024 8:25508-09
123HariManager5/2/2024 11:345/2/2024 11:491511-12
123HariManager5/2/2024 11:175/2/2024 11:321511-12
4 REPLIES 4
danextian
Super User
Super User

Hi @PowerBigginer 

 

For record #1:

  • why is the interval 8-9 when the range is from 8-11?
  • how many rows do you expect to see as the result?

Please provide expected result using the sample data.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Business requirement is to track how many hours he was in online. And I am not expecting in the row I am adding this in matrix visual 

I asked because you mentioned that "we want to calculate the time spent for each hourly interval" which I assumed you wanted to show each interval as a row.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
PowerBigginer
Helper II
Helper II

I tried with this dax but not getting expected result 

HourlyDifference =
VAR LoggedInHour = HOUR(MAX(Tbl_Login[Logged In Time]))  -- Get the hour of login
VAR LoggedOutHour = HOUR(MAX(Tbl_Login[Logged Out Time]))  -- Get the hour of logout
VAR LoggedOutMinute = MINUTE(MAX(Tbl_Login[Logged Out Time]))  -- Get the minute of logout
VAR LoggedInMinute = MINUTE(MAX(Tbl_Login[Logged In Time]))  -- Get the minute of login

RETURN
    IF(
        LoggedInHour = LoggedOutHour,  -- If login and logout are in the same hour
        LoggedOutMinute - LoggedInMinute,  -- Calculate the difference in minutes
        IF(
            LoggedOutHour = LoggedInHour + 1,  -- If logout is in the next hour
            60 - LoggedInMinute,  -- Calculate the remaining minutes in the login hour
            IF(
                LoggedInHour < 12,  -- If login hour is before 12
                60,  -- Full hour for the login hour
                IF(
                    LoggedOutHour > 0,  -- If logout hour is after 0 (midnight)
                    LoggedOutMinute,  -- Remaining minutes until logout
                    0  -- Default value if logout is not after midnight
                )
            )
        )
    )

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.