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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TatyDo
Helper III
Helper III

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

@TatyDo , 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"

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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