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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

M Query If Statement for Dates and time

Hallo Everone,

I need help to transform the folowing situation into M query. 

I hava the folowing situation, where I need to distinguish my DB in two stagges. where the condition of "Morning" , "Evening" and "night"changes over time. 

 

data that are before 04.02.2018 then if time is between 10:00 and 12:00 then "Morning" and between 12:00 and 18:00 is "Evening" later is "Night" and the data after 04.02.2018 then if time is between 09:00 and 11:00 then "Morning" and between 11:00 and 17:00 is "Evening" later is "Night"

 

I want to do it directly in the Query so using M language , I am not looking for a measure.

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Try a new column in M-like. As I was not sure on month so, change as per need

 

if DateTime.Date([Date]) <#date(2018,02,04)
if DateTime.Time([Date]) >= #time(10,0,0) and DateTime.Time([Date]) >= #time(12,0,0) then "Morning" else
if DateTime.Time([Date]) >= #time(12,0,0) and DateTime.Time([Date]) >= #time(18,0,0) then "Evening" else "Night"
else
if DateTime.Time([Date]) >= #time(9,0,0) and DateTime.Time([Date]) >= #time(11,0,0) then "Morning" else
if DateTime.Time([Date]) >= #time(11,0,0) and DateTime.Time([Date]) >= #time(17,0,0) then "Evening" else "Night"

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thank you so much!, I needed to change some <> signs to fit and add then but it worked great 🙂 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors