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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
pborah
Impactful Individual
Impactful Individual

Please help with power query conditional column

I'm trying to group time data into day shift and night shift using custom column in power query

 

pborah_0-1707499525124.png

 

I tried a few variations but can't seem to get it right. The conditional statement either executes but has no results or there's some syntax error that does now allow me to execute the statement. The statement has a logical operator AND in it so I can't use the "conditional column" in power query.

 

pborah_1-1707499658822.png pborah_2-1707499717422.png

 

pborah_3-1707499837286.png

The last one executes, but the resultant column simply shows "Error" instead of values. Thank you.

 

 

 

1 ACCEPTED SOLUTION
Idrissshatila
Super User
Super User

Hello @pborah ,

 

try the following custom column

 

if DateTime.Time([received_time]) >= #time(6,0,0) and DateTime.Time([received_time]) < #time(18,0,0)  then "Day" else "Night"


Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Idrissshatila
Super User
Super User

Hello @pborah ,

 

try the following custom column

 

if DateTime.Time([received_time]) >= #time(6,0,0) and DateTime.Time([received_time]) < #time(18,0,0)  then "Day" else "Night"


Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Ritaf1983
Super User
Super User

Hi @pborah 
Please refer to the solution of @amitchandak  in the linked discussion :
https://community.fabric.microsoft.com/t5/Desktop/M-Query-If-Statement-for-Dates-and-time/td-p/17860...

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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