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
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.

Krutigawale33
Responsive Resident
Responsive Resident

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
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.