The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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
Solved! Go to Solution.
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)
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)
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
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
80 | |
73 | |
52 | |
50 |
User | Count |
---|---|
129 | |
123 | |
78 | |
64 | |
60 |