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

How to LOOKUP day name based on date+time column to make the "DAY" 6AM-5:59AM and not 12-12

Hi All,

 

Hoping there's a real simple solution out there, but I need to report on days from 6am to 6am as that's how the shifts run and production volumes are measure as such. So for my reports to make sense the days need to stretch from 6-6 and not 12-12, ie all data entries between date and time 27 Aug 6AM-28 Aug 5:59AM would be classified as Monday. However, using the "ADD COLUMN>DATE>DAY>NAME OF DAY" functionality when editing queries in BI desktop I obviously get a day name based on the date.

 

I hope my question is clear? Perhaps the table below is a better example:

 

OrderMalfunct. startStart Malfn (T)Day Name (using query or formula)Day Name (required output)
1000111583662018/01/2906:47:0011
1000111607122018/01/2922:33:5711
1000111621892018/01/2922:39:0011
1000111607802018/01/3000:02:5621
1000111620672018/01/3000:32:4621
1000111622922018/01/3002:39:1321
1000111621492018/01/3003:00:0021
1000111621492018/01/305:59:0021
1000111621492018/01/306:00:0022
1000111621492018/01/3013:00:0022
1000111621492018/01/3023:59:0022
1000111621492018/01/3112:00:0032
1000111621492018/01/315:59:0032
1000111621492018/02/016:00:0043
1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

you will have to change the [Malfunct. start] to type date time and then you can use this syntax when you add new column - it takes the time of malfunciton time and subtracts 6h to get the result you wanted

Date.DayOfWeek(
[Malfunct. start] 
+ #duration(0,Time.Hour([#"Start Malfn (T)"]),Time.Minute([#"Start Malfn (T)"]),Time.Second([#"Start Malfn (T)"]))
- #duration(0,6,0,0)
,0)

PS the expected output for the

2018/01/3112:00:00

is inconsistent with the description, it should be 3 as the resutl of the formula, correct?

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

hi,@Philip0123

  After my research, you can do these follow my steps like below:

Step 1:

Continue to use the "ADD COLUMN>DATE>DAY>NAME OF DAY" functionality to add the column Day Name (using query or formula) then add column start time:

Start time = "6:00:00"

and change the data type to time.

Step 2:

change the data type of column Day Name (using query or formula) to Whole number and add the column 

Day Name = IF(Table1[Start Malfn (T)]<Table1[Start time],(Table1[Day Name (using query or formula)]-1),Table1[Day Name (using query or formula)])

Result:

1.PNG

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Stachu
Community Champion
Community Champion

you will have to change the [Malfunct. start] to type date time and then you can use this syntax when you add new column - it takes the time of malfunciton time and subtracts 6h to get the result you wanted

Date.DayOfWeek(
[Malfunct. start] 
+ #duration(0,Time.Hour([#"Start Malfn (T)"]),Time.Minute([#"Start Malfn (T)"]),Time.Second([#"Start Malfn (T)"]))
- #duration(0,6,0,0)
,0)

PS the expected output for the

2018/01/3112:00:00

is inconsistent with the description, it should be 3 as the resutl of the formula, correct?

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂


@Stachu wrote:

you will have to change the [Malfunct. start] to type date time and then you can use this syntax when you add new column - it takes the time of malfunciton time and subtracts 6h to get the result you wanted

Date.DayOfWeek(
[Malfunct. start] 
+ #duration(0,Time.Hour([#"Start Malfn (T)"]),Time.Minute([#"Start Malfn (T)"]),Time.Second([#"Start Malfn (T)"]))
- #duration(0,6,0,0)
,0)

PS the expected output for the

2018/01/3112:00:00

is inconsistent with the description, it should be 3 as the resutl of the formula, correct?

 



Awesome, this works like a bomb. 

 

Just a quick follow up, I'm not that familiar with the M language, how do I replace the output (1-7) with the actual day names? Using DAX I can simply use the switch function, but not sure with M. Sorry, I realise that wasn't part of the original  problem description.

 

Also, 00:00 on 31st is technically Wednesday, or output would be 3. But we include everything on Wednesday up until 06:00 in Tuesday's figures, so it should be 2, or Tuesday.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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