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

Converting DAX to M

Hi team,

I have the following calculated column (DAX):
Shift = IF(AND('Table'[Time]>=TIMEVALUE("12:00 AM"),'Table'[Time]<TIMEVALUE("7:00 AM")),"N",IF(AND('Table'[Time]>=TIMEVALUE("7:00 AM"),'Table[Time]<TIMEVALUE("2:00 PM")),"D",IF(AND('Table'[Time]>=TIMEVALUE("2:00 PM"),'Table'[Time]<TIMEVALUE("5:00 PM")),"B","A")))

I would like to add new column (representing the same DAX formula requirements) in the Advanced query source code (Power M).
Can you help me transforming the dax formula into power m code?

Thank you.

1 ACCEPTED SOLUTION

@Anonymous , My bad in power query and is and not &&

 

if [Time] >= #time(0,0,0) and [Time] < #time(7,0,0) then "N"
else if [Time] >= #time(7,0,0) and  [Time] < #time(14,0,0) then "D"
else if [Time] >= #time(14,0,0) and [Time] < #time(17,0,0) then "B" else "A"

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

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Try like

 


if [Time] >= #time(0,0,0) && [Time] < #time(7,0,0) then "N"
else if [Time] >= #time(7,0,0) && [Time] < #time(14,0,0) then "D"
else if [Time] >= #time(14,0,0) && [Time] < #time(17,0,0) then "B" else "A"

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

Hi @amitchandak,

Thank you for your response. I tried to create a custom column with the suggested code, but I received an error "Token Literal expected" and the letter 'm' in column [Time] was underlined. 
scr1.png

I know that this error means that the next thing in the formula is expected to be a value, column name, or a function, and in my case is a column name (with type 'time'). Do you have any ideas how can I edit this code in order to remove the error?

Thanks.

@Anonymous , My bad in power query and is and not &&

 

if [Time] >= #time(0,0,0) and [Time] < #time(7,0,0) then "N"
else if [Time] >= #time(7,0,0) and  [Time] < #time(14,0,0) then "D"
else if [Time] >= #time(14,0,0) and [Time] < #time(17,0,0) then "B" else "A"

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

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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