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
Anonymous
Not applicable

Help With SWITCH Function - DAX Check Request

My goal is to take hours in the day and put them into buckets. The calculated column output is all NULL values. I can't seem to get the DAX correct. Any advice you can provide on where I am going wrong is greatly appreciated. 

 

8hr Time Band =
SWITCH(
TRUE(),
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 1,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 😎 ) , "1:00 AM - 8:00 AM",
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 9,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 16) ) , "9:00 AM - 4:00 PM",
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 17,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 0) ), "5:00 PM - 12:00 AM"
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

I was able to find the solution to my own problem by changing the ordering of the hour inputs. It is best to start with the midnight hour (0) and work up from there. 

 

8hr Time Band =
SWITCH(
TRUE(),
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 0,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 7) ) , "12:00 AM - 7:00 AM",
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 8,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 15) ) , "8:00 AM - 3:00 PM",
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 16,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 23) ), "4:00 PM - 11:00 PM"
)

View solution in original post

1 REPLY 1
Anonymous
Not applicable

I was able to find the solution to my own problem by changing the ordering of the hour inputs. It is best to start with the midnight hour (0) and work up from there. 

 

8hr Time Band =
SWITCH(
TRUE(),
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 0,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 7) ) , "12:00 AM - 7:00 AM",
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 8,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 15) ) , "8:00 AM - 3:00 PM",
AND(
DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) >= 16,
(DATEDIFF( 'Time'[HourNum], 'Time'[HourNum], HOUR ) <= 23) ), "4:00 PM - 11:00 PM"
)

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.