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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
pborah
Solution Sage
Solution Sage

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
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.

Top Solution Authors