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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DebbieE
Community Champion
Community Champion

M Code for where date Between Date 1 and Date 2

I have a date table with the following columns

 

Date,               LatestReportDate, 5YearsPreLatestreportdate

01/01/2014    01/01/2019             01/01/2014

02/01/2014    01/01/2019              01/01/2014

03/01/2014    01/01/2019               01/01/2014

 

I want to create a conditional Column, where Date Between LatestreportDate and 5yearsLatestReportDate Then True

Else False

 

But Im struggling with the syntax

 

If anyone could pop me across the proper syntax for M. That would be great

                     

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hello @DebbieE

Place the following M code in a blank query to see the steps. The last step is the important one:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDWNzDUNzIwNFbSUQKyIBxLZI6JUqxONDKXgEIjYhTGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, LatestReportDate = _t, #"5YearsPreLatestreportdate" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"LatestReportDate", type date}, {"5YearsPreLatestreportdate", type date}}),

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Date] <= [LatestReportDate] and [Date] >= [5YearsPreLatestreportdate] then true else false)
in
    #"Added Custom"

Please mark the resolved question when you are finished and consider giving a thumbs up if the posts are useful.

Contact me privately for assistance with any large-scale BI needs, tutoring, etc.

Bless you

SU18_powerbi_badge

View solution in original post

2 REPLIES 2
DebbieE
Community Champion
Community Champion

Thanks so much. Worked a treat

AlB
Community Champion
Community Champion

Hello @DebbieE

Place the following M code in a blank query to see the steps. The last step is the important one:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDWNzDUNzIwNFbSUQKyIBxLZI6JUqxONDKXgEIjYhTGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, LatestReportDate = _t, #"5YearsPreLatestreportdate" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"LatestReportDate", type date}, {"5YearsPreLatestreportdate", type date}}),

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Date] <= [LatestReportDate] and [Date] >= [5YearsPreLatestreportdate] then true else false)
in
    #"Added Custom"

Please mark the resolved question when you are finished and consider giving a thumbs up if the posts are useful.

Contact me privately for assistance with any large-scale BI needs, tutoring, etc.

Bless you

SU18_powerbi_badge

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.