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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Marco3007
Frequent Visitor

Help creating custom column based on time interval

Greetings!

 

I have tried, without much knowledge other than some experience, to create a visual that displays incident tickets handled by my team.

 

I want to present how many tickets have been created and taken care of, either monthly or year-to-date, and that is easy but I would like to show intervals of when they were created. We have 2 shifts, one from 6:30AM - 4:00PM and the other 4:00PM - 1:15AM. I have a column with time and date, so I copied it and split it to get just the time (properly formatted as so), and now I would like to create a column that displays one of the following values:

 

6h - 8h30

8h30 - 11h

11h - 13h30

13h30 - 16h

16h - 19h

19h - 21h

21h - 2h

2h - 6h (out of bh)

 

I tried to apply the logic behind what I want with M in Power Query and DAX in Create Costum Column, but either way I think I am confusing a bit on the syntax of the rules. Basically, the idea is (disregard it as a code, it is just how I thought of it):

 

New Column Name = INC_CreationPeriod

INC_CreationPeriod = if (data on column) time >= 06:00:00 and time <= 08:29:59, then (fill in as) "6h - 8h30";

                            or if time >= 08:30:00 and time <= 10:59:59, then "8h30 - 11h";

                            or if time >= 11:00:00 and time <= 13:29:59, then "11h - 13h30";

                            ...and so on for all the time intervals...

                            or if time >= 21:30:00 and time <= 01:59:59, then "21h - 2h"; 

                            and finally, if time does not fall within these parameters above, fill in as "2h - 6h (out of bh)"

 

I spent quite a while trying to figure it out, simplifying it as much as possible, careful when using if / else operators, trying to unscramble the time format, converting... but eventually getting caught in errors. I also tried little by little, but even when the first field (6h - 8h30) works, the others don't...

 

Any ideas on how to work around it?

I can get more details of the table if needed. 

 

Thank you all very much!

2 ACCEPTED SOLUTIONS

hi @Marco3007 

try to add a calculated column like:

column = 
SWITCH(
    TRUE(),
    [INC_Time]<5/24, "2h- 5h(out of bh)",
    [INC_Time]<8.5/24, "6h- 8h30",
    [INC_Time]<11/24, "8h30- 11h",
    [INC_Time]<16/24, "13h30- 16h",
    [INC_Time]<19/24, "16h- 19h",
    "21h -22h"
)

it worked like:

FreemanZ_0-1684579378531.png

View solution in original post

Thank you very much, @FreemanZ!  I will try your suggestion. I had been struggling for a while and eventually made it work with AND function, as well as &&. In the end this is how I set it, but I will give it a try with your code, too:

 

INC_CreationPeriod = IF([INC_TimeOnly]>=time(6,0,0)&&[INC_TimeOnly]<=time(8,29,59), "6h - 8h30",
IF([INC_TimeOnly]>=time(8,30,0)&&[INC_TimeOnly]<=time(10,59,59), "8h30 - 11h",
IF([INC_TimeOnly]>=time(11,0,0)&&[INC_TimeOnly]<=time(13,29,59), "11h - 13h30",
IF([INC_TimeOnly]>=time(13,30,0)&&[INC_TimeOnly]<=time(15,59,59), "13h30 - 16h",
IF([INC_TimeOnly]>=time(16,0,0)&&[INC_TimeOnly]<=time(18,59,59), "16h - 19h",
IF([INC_TimeOnly]>=time(19,0,0)&&[INC_TimeOnly]<=time(21,29,59), "19h - 21h30",
IF([INC_TimeOnly]>=time(21,30,0)&&[INC_TimeOnly]<=time(1,59,59), "21h30 - 2h", "2h - 6h (out of BH)")))))))
 
 
Thanks a lot once again!

View solution in original post

3 REPLIES 3
Marco3007
Frequent Visitor

An example of what I expect (using made up data):

 

Marco3007_0-1684429913981.png

 

hi @Marco3007 

try to add a calculated column like:

column = 
SWITCH(
    TRUE(),
    [INC_Time]<5/24, "2h- 5h(out of bh)",
    [INC_Time]<8.5/24, "6h- 8h30",
    [INC_Time]<11/24, "8h30- 11h",
    [INC_Time]<16/24, "13h30- 16h",
    [INC_Time]<19/24, "16h- 19h",
    "21h -22h"
)

it worked like:

FreemanZ_0-1684579378531.png

Thank you very much, @FreemanZ!  I will try your suggestion. I had been struggling for a while and eventually made it work with AND function, as well as &&. In the end this is how I set it, but I will give it a try with your code, too:

 

INC_CreationPeriod = IF([INC_TimeOnly]>=time(6,0,0)&&[INC_TimeOnly]<=time(8,29,59), "6h - 8h30",
IF([INC_TimeOnly]>=time(8,30,0)&&[INC_TimeOnly]<=time(10,59,59), "8h30 - 11h",
IF([INC_TimeOnly]>=time(11,0,0)&&[INC_TimeOnly]<=time(13,29,59), "11h - 13h30",
IF([INC_TimeOnly]>=time(13,30,0)&&[INC_TimeOnly]<=time(15,59,59), "13h30 - 16h",
IF([INC_TimeOnly]>=time(16,0,0)&&[INC_TimeOnly]<=time(18,59,59), "16h - 19h",
IF([INC_TimeOnly]>=time(19,0,0)&&[INC_TimeOnly]<=time(21,29,59), "19h - 21h30",
IF([INC_TimeOnly]>=time(21,30,0)&&[INC_TimeOnly]<=time(1,59,59), "21h30 - 2h", "2h - 6h (out of BH)")))))))
 
 
Thanks a lot once again!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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