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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ElliotP
Post Prodigy
Post Prodigy

Show Word if between Two Dates

Evening,

 

I'm trying to create a column for dates which will show different categorisations depending upon the date range. The date ranges aren't within my table and I'm trying to code them into the M/column.

 

When I attempted to create the column in the report view with the code it returns "returns multiple values":

Tester2021 = IF(DATESBETWEEN('itemdetailsdogfood$'[Date], DATE(2017,1,1), DATE(2017,7,15)),"Term Time", "Normal")

When I create the custom column in the query editor, I'm not sure of the syntax for M:

 

 

if([Date] > DATE(2017,1,1) < DATE(2017,7,15), "Term Time", "Normal")

Thoughts or suggestions? I've searched the forums and the internet to no avail. I've had a look at the M reference, but that seems to be focused upon power query as opposed to the M used in Custom Columns.

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @ElliotP,

 

Add a custom column with the following code:

 

= 
 if 
 [Date] >=  #date(2017, 1, 1)  and [Date]  <=   #date(2017, 7, 15) 
then "Term Time"

else "Normal"

 

The M code is:

= Table.AddColumn(#"Renamed Columns", "Custom.1", each if 
 [Date] >=  #date(2017, 1, 1) 
and [Date]  <=   #date(2017, 7, 15) 
then "Term Time"

else "Normal")

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @ElliotP,

 

Add a custom column with the following code:

 

= 
 if 
 [Date] >=  #date(2017, 1, 1)  and [Date]  <=   #date(2017, 7, 15) 
then "Term Time"

else "Normal"

 

The M code is:

= Table.AddColumn(#"Renamed Columns", "Custom.1", each if 
 [Date] >=  #date(2017, 1, 1) 
and [Date]  <=   #date(2017, 7, 15) 
then "Term Time"

else "Normal")

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you so much, I greatly appreciate it.

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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.