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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Column to set a value if date is between two dates with M language?

I have a Sub Date column that simply has dates: 1/1/2020, 1/16/2020, etc. I want to add a custom column in the query that checks IF the date is between first of the month to the 8th of the month, and if so, set value to either TRUE or 1 to signify it's within that date range

 

How can I achieve this in M? 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

You may add a custom column with the following m codes.

=if Date.Day([Sub Date])>=1 and Date.Day([Sub Date])<=8 
then 1 else 0

c2.png

 

 

Result:

c3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

You may add a custom column with the following m codes.

=if Date.Day([Sub Date])>=1 and Date.Day([Sub Date])<=8 
then 1 else 0

c2.png

 

 

Result:

c3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hello @Anonymous ,

 

Please find the steps to achieve the result in query editor.

 

let
Source = Excel.Workbook(File.Contents("C:\Users\kgawale\Documents\Test 15 March 2021.xlsx"), null, true),
Sheet7_Sheet = Source{[Item="Sheet7",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet7_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Contract Date", type date}}),
#"Inserted Month" = Table.AddColumn(#"Changed Type", "Month", each Date.Month([Contract Date]), Int64.Type),
#"Added Conditional Column" = Table.AddColumn(#"Inserted Month", "Custom.1", each if [Month] <= 8 then 1 else 0)
in
#"Added Conditional Column"

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Kudoed Authors