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
kvitnitskiy
Frequent Visitor

DAX dates between 08:00 and 20:00

Hello all,

 I just started use POwerBI ind found it super nice.

 my question is, hot to create new column with next data:

if datetime  is betwean 08:00 - 20:00 -  return date & 08-20

if datetime is  betvean 20:00-08:00 next day - return date & 20:08

 like in table below. 
  

Check_In_Date  DAX
27.04.2020 9:30 27.04.2020  08-20
27.04.2020 10:14 27.04.2020  08-20
27.04.2020 10:44 27.04.2020  08-20
27.04.2020 15:12 27.04.2020  08-20
27.04.2020 15:31 27.04.2020  08-20
27.04.2020 20:01 27.04.2020  20-08
27.04.2020 21:04 27.04.2020  20-08
27.04.2020 22:03 27.04.2020  20-08
28.04.2020 2:09 27.04.2020  20-08
28.04.2020 7:39 27.04.2020  20-08
28.04.2020 10:18 28.04.2020  08-20
28.04.2020 11:13 28.04.2020  08-20
28.04.2020 11:44 28.04.2020  08-20
1 ACCEPTED SOLUTION

Please try this modified one.  I should have done it this way first time.

 

NewDAXColumn =
SWITCH (
TRUE (),
HOUR ( CheckIn[ConvertedDateTime] ) < 8, DAY ( CheckIn[ConvertedDateTime]-1)  & "."
& MONTH ( CheckIn[ConvertedDateTime] -1) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 20-08",
HOUR ( CheckIn[ConvertedDateTime] ) >= 20, DAY ( CheckIn[ConvertedDateTime] ) & "."
& MONTH ( CheckIn[ConvertedDateTime] ) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 20-08",
DAY ( CheckIn[ConvertedDateTime] ) & "."
& MONTH ( CheckIn[ConvertedDateTime] ) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 08-20"
)





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a DAX expression that will get your result.  I had to made a DateTime column from your input date, so you may have to do the same first.  I called my DateTime column 'ConvertedDateTime'.

 

NewDAXColumn =
SWITCH (
TRUE (),
HOUR ( CheckIn[ConvertedDateTime] ) < 8, DAY ( CheckIn[ConvertedDateTime] ) - 1 & "."
& MONTH ( CheckIn[ConvertedDateTime] ) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 20-08",
HOUR ( CheckIn[ConvertedDateTime] ) >= 20, DAY ( CheckIn[ConvertedDateTime] ) & "."
& MONTH ( CheckIn[ConvertedDateTime] ) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 20-08",
DAY ( CheckIn[ConvertedDateTime] ) & "."
& MONTH ( CheckIn[ConvertedDateTime] ) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 08-20"
)

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks,  this is almost i need, except this small issue at the begining  of month.

2020-05-28_155933.png

 

 

Please try this modified one.  I should have done it this way first time.

 

NewDAXColumn =
SWITCH (
TRUE (),
HOUR ( CheckIn[ConvertedDateTime] ) < 8, DAY ( CheckIn[ConvertedDateTime]-1)  & "."
& MONTH ( CheckIn[ConvertedDateTime] -1) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 20-08",
HOUR ( CheckIn[ConvertedDateTime] ) >= 20, DAY ( CheckIn[ConvertedDateTime] ) & "."
& MONTH ( CheckIn[ConvertedDateTime] ) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 20-08",
DAY ( CheckIn[ConvertedDateTime] ) & "."
& MONTH ( CheckIn[ConvertedDateTime] ) & "."
& YEAR ( CheckIn[ConvertedDateTime] ) & " 08-20"
)





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.