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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
stan255
New Member

How to check if Date A is X days before Date B?

I have two date columns - Date A and Date B.

How can I check if Date A is within 7 days before any of Date B?

compare 2 date.png

2 ACCEPTED SOLUTIONS
Omid_Motamedise
Super User
Super User

Copy the below code and paste it into the advance editor.

let
    TableA = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY9LDoAgDETv0rUJ7YCCZ2m4/zXEFZ2auHzJfN3FatFRoGgyDxdchIvuTbawbxwktVZMA3a2DrKCWw08wj7iGFWpKC1+vUGMzlEnYVrFh6r+PkjBYHE4NB8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable date) meta [Serialized.Text = true]) in type table [Date = _t]),
    TableAChangedType = Table.TransformColumnTypes(TableA,{{"Date", type date}}),
    TableB = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtc3sNQ3MjAyUYrViVYyNEbhmqHwTPQNDRA8CxQ5I6A5FriUGhugqDVHkTSyROiMBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable date) meta [Serialized.Text = true]) in type table [Date = _t]),
    TableBChangedType = Table.TransformColumnTypes(TableB,{{"Date", type date}}),
    Custom1 = Table.AddColumn(TableAChangedType, "Flag", each not Table.IsEmpty(Table.SelectRows(TableBChangedType, (x)=> x[Date]>=[Date] and Date.AddDays(x[Date],-7)<=[Date])))
in
    Custom1

 

I have added a new column into Table A with true value for the rows which are with in the 7 days of at least a date in Table B

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

Anonymous
Not applicable

Hi,

Thanks for the solutions @Omid_Motamedise  and @jgeddes  offered, and i want to offer some more information for user to refer to.

hello @stan255 , baded on your picture, your two date columns come from different tables, in table A , you can create a cusotm column.

 

let a=Query2[reportedDate],
b=[Open],
c=List.Count(List.Select(a,each b>=Date.AddDays(_,-7) and b<=_))
in if c>0 then "Y" else "N"

 

vxinruzhumsft_1-1730084928669.png

 

Output

vxinruzhumsft_0-1730084667251.png

You can refer to the attachment.

 

Best Regards!

Yolo Zhu

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

4 REPLIES 4
Omid_Motamedise
Super User
Super User

Copy the below code and paste it into the advance editor.

let
    TableA = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY9LDoAgDETv0rUJ7YCCZ2m4/zXEFZ2auHzJfN3FatFRoGgyDxdchIvuTbawbxwktVZMA3a2DrKCWw08wj7iGFWpKC1+vUGMzlEnYVrFh6r+PkjBYHE4NB8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable date) meta [Serialized.Text = true]) in type table [Date = _t]),
    TableAChangedType = Table.TransformColumnTypes(TableA,{{"Date", type date}}),
    TableB = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtc3sNQ3MjAyUYrViVYyNEbhmqHwTPQNDRA8CxQ5I6A5FriUGhugqDVHkTSyROiMBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable date) meta [Serialized.Text = true]) in type table [Date = _t]),
    TableBChangedType = Table.TransformColumnTypes(TableB,{{"Date", type date}}),
    Custom1 = Table.AddColumn(TableAChangedType, "Flag", each not Table.IsEmpty(Table.SelectRows(TableBChangedType, (x)=> x[Date]>=[Date] and Date.AddDays(x[Date],-7)<=[Date])))
in
    Custom1

 

I have added a new column into Table A with true value for the rows which are with in the 7 days of at least a date in Table B

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
jgeddes
Super User
Super User

Something like this might work for you...

jgeddes_0-1729703107531.png

 





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

Proud to be a Super User!





Thanks for this solution. I'm getting this error

"DataFormat.Error: We couldn't convert to Date.
Details:
[List]"

Anonymous
Not applicable

Hi,

Thanks for the solutions @Omid_Motamedise  and @jgeddes  offered, and i want to offer some more information for user to refer to.

hello @stan255 , baded on your picture, your two date columns come from different tables, in table A , you can create a cusotm column.

 

let a=Query2[reportedDate],
b=[Open],
c=List.Count(List.Select(a,each b>=Date.AddDays(_,-7) and b<=_))
in if c>0 then "Y" else "N"

 

vxinruzhumsft_1-1730084928669.png

 

Output

vxinruzhumsft_0-1730084667251.png

You can refer to the attachment.

 

Best Regards!

Yolo Zhu

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

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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 Kudoed Authors