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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
runnerpaul
Regular Visitor

Create Morning/Afternoon columns based on DateTime column

Hi,

 

I have a table with a datetime column called CREATEDDATETIME. I want to use it to create a new column where depending on the time it gets populated with Morning or Afternoon. Anything before 13:00 would be morning and anything after would be Afternoon. Is this possible and if so how do I do it?

 

Cheers

Paul

1 ACCEPTED SOLUTION
SamLester
Microsoft Employee
Microsoft Employee

Hi Paul, you can use the HOUR function in an IF statement to calculate this.

 

Example:

MorningAfternoon = if((HOUR(TimeTable[CREATEDDATETIME]) <= 12), "Morning", "Afternoon")

 

Thanks,
Sam Lester (MSFT)

View solution in original post

3 REPLIES 3
SamLester
Microsoft Employee
Microsoft Employee

Hi Paul, you can use the HOUR function in an IF statement to calculate this.

 

Example:

MorningAfternoon = if((HOUR(TimeTable[CREATEDDATETIME]) <= 12), "Morning", "Afternoon")

 

Thanks,
Sam Lester (MSFT)

Anonymous
Not applicable

This worked, thank you.

Hi @SamLester ,

I just have another follow up question regarding shift system that I'm trying to create in power bi and hope you have some solution.

In my case I need to create based on the day, for example if it's monday or tuesday etc., so in Excel I used Switch function as follows. I could do this by "IF" but it's going to be a very long formula so I was wondering if there's any better way.

SWITCH([@Day];"mon";LOOKUP([@Hour];{0;6;15};{"N";"FM";"EM"});"tue";LOOKUP([@Hour];{0;6;15};{"N";"FM";"EM"});"wed";LOOKUP([@Hour];{0;6;15};{"N";"FM";"EM"});"thu";LOOKUP([@Hour];{0;6;15};{"N";"FM";"EM"});"fri";LOOKUP([@Hour];{0;6;15};{"N";"FM";"N14"});"Sat";LOOKUP([@Hour];{0;5;18};{"N14";"D13";"N14"});"sun";LOOKUP([@Hour];{0;8;18};{"N14";"D13";"N"});"") 

where N= night, FM= morning and EM= afternoon etc.  

 

Thank you in advance,

/Kranthi

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.