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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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.










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


Proud to be a Super User!









"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.










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


Proud to be a Super User!









"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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.