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
smjzahid
Helper V
Helper V

How to use Datediff in power query

I want to create a conditional or a custom column within Power Query (using M) and NOT DAX, Here is my requirement

 

if [Consent Application Submitted] is not blank and [Consent Application Submitted] > 6 Weeks from today then "White"

 

if [Consent Application Submitted] is not blank and [Consent Application Submitted] < 6 Weeks from today then "Red"

 

I know I can do this using DAX (DATEDIFF). However, I want to create a column using Power Query. 

 

Is there a way to achieve this in Power Query or the M code. 

 

 

 

 

 

 

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

Hi @smjzahid ,

 

You could refer to the following codes:

if
Duration.Days(Date.From(DateTime.LocalNow())-[Date])>42
then "White"
else "Red"

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @smjzahid ,

 

You could refer to the following codes:

if
Duration.Days(Date.From(DateTime.LocalNow())-[Date])>42
then "White"
else "Red"

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
camargos88
Community Champion
Community Champion

Hi @smjzahid ,

 

Try this one:

 

if [Date] > Date.AddWeeks(Date.From(DateTime.LocalNow()), 6) then
"White"
else
"Red"

 

Capture.PNG



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

Proud to be a Super User!



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.