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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
ADSL
Post Prodigy
Post Prodigy

Time Tracking with time group

Hi BI Community Team,

 

As per expectation result, we want to know the earliest of check-in time and latest of check-out time by time group as the screenshot below:

 

So, we have tired the new column with measure below.

 

Time_Group2 = SWITCH(TRUE(),
[Check-In] >= TIME(1,0,0) && [Check-Out] < TIME(8,0,0), "Early Morning",
[Check-In] >= TIME(8,0,0) && [Check-Out] < TIME(12,0,0), "Morning",
[Check-In] >= TIME(12,0,0) && [Check-Out] < TIME(13,30,0), "Lunch",
[Check-In] >= TIME(13,30,0) && [Check-Out] < TIME(17,30,0), "Afternoon",
[Check-In] >= TIME(17,30,0) && [Check-Out] < TIME(21,0,0), "Evening", "Late Evening")
 
then we found that time group is showing wrong if value of check-out is blank. normally, value of check-out will be the same as check-in if it's blank.
 
Any suggestion/advise?
 
2023-08-10_21-54-52.png
 
Thanks and Regards,
 
 
5 REPLIES 5
AmiraBedh
Super User
Super User

I adjusted your dax code to the following : 

Time_Group2 = 


SWITCH(
    TRUE(),
    ISBLANK([Check-Out]), SWITCH(
        TRUE(),
        [Check-In] >= TIME(1, 0, 0) && [Check-In] < TIME(8, 0, 0), "Early Morning",
        [Check-In] >= TIME(8, 0, 0) && [Check-In] < TIME(12, 0, 0), "Morning",
        [Check-In] >= TIME(12, 0, 0) && [Check-In] < TIME(13, 30, 0), "Lunch",
        [Check-In] >= TIME(13, 30, 0) && [Check-In] < TIME(17, 30, 0), "Afternoon",
        [Check-In] >= TIME(17, 30, 0) && [Check-In] < TIME(21, 0, 0), "Evening",
        "Late Evening"
    ),
    [Check-In] >= TIME(1, 0, 0) && [Check-Out] < TIME(8, 0, 0), "Early Morning",
    [Check-In] >= TIME(8, 0, 0) && [Check-Out] < TIME(12, 0, 0), "Morning",
    [Check-In] >= TIME(12, 0, 0) && [Check-Out] < TIME(13, 30, 0), "Lunch",
    [Check-In] >= TIME(13, 30, 0) && [Check-Out] < TIME(17, 30, 0), "Afternoon",
    [Check-In] >= TIME(17, 30, 0) && [Check-Out] < TIME(21, 0, 0), "Evening",
    "Late Evening"
)

AmiraBedh_0-1691691284698.png

 

The code you provided doesn't handle the case where the "Check-Out" value is blank. In your provided logic, you directly compare "Check-In" and "Check-Out" times without considering the scenario when "Check-Out" is blank.

Since the code does not include any conditional check to handle a blank "Check-Out" value, it may lead to incorrect results in that specific case. If "Check-Out" is blank, the code does not have any instruction on how to handle that scenario, so it may lead to wrong categorizations or unexpected results.

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Hi @AmiraBedh ,

 

After trying and check then I see some times assigned to wrong time group as the screenshot.

 

2023-08-12_06-27-00.png

 

Any suggestion?

 

Thanks and Regards,

Is it related to Time_Group2 or another calculated columns? Can you please be more clear in your explanation ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Hi Amira,

 

It's related to Time_Group2. If you check the screenshot below and yellow highlight, you will see the time of check-in & check-out. It should be in Lunch or afternoon in Time_Group2.

 

But it's showed "Late Evening" that it's not correct of time group.

 

2023-08-12_19-27-02.png

 

Please kindly advise and check.

 

Thanks and Regards,

Can you please provide your logic case by case ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.