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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Jay2077
Helper III
Helper III

IF less than today with dax

So i have a column of dates and i want to add a column which contains a formula saying if that data is before today then "yes" else "no" 

 

when you do the conditional column and say before you can put a date but not TODAY()  How do i replace 2121, 1, 1 with TODAY()  ?

 

= Table.AddColumn(#"Renamed Columns", "Custom", each if [#"Expiry"] <= #date(2021, 1, 1) then "Expired" else "Not-Expired")

2 ACCEPTED SOLUTIONS
edhans
Super User
Super User

Greg is right - to be specific, change your formula to this

Table.AddColumn(#"Renamed Columns", "Custom", each if [#"Expiry"] <= DateTime.Date(DateTime.LocalNow()) then "Expired" else "Not-Expired")

 

DateTime.LocalNow() is equivalent to NOW() in Excel.
Wrapping it in DateTime.Date() converts it to just the day - strips the time off of it, so it will do the comparison correctly.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

In Power Query? You could group by the new column and use COUNT as the aggregation, but I'd be inclined to that in DAX, as that is analysis. So

Expired Count =
CALCULATE(
    COUNTROWS( MyTable ),
    MyTable[ExpiredField] = "Expired"
)





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

5 REPLIES 5
edhans
Super User
Super User

Greg is right - to be specific, change your formula to this

Table.AddColumn(#"Renamed Columns", "Custom", each if [#"Expiry"] <= DateTime.Date(DateTime.LocalNow()) then "Expired" else "Not-Expired")

 

DateTime.LocalNow() is equivalent to NOW() in Excel.
Wrapping it in DateTime.Date() converts it to just the day - strips the time off of it, so it will do the comparison correctly.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

This is great thanks how would i go about counting rows of expired and non expired from there then please ?

In Power Query? You could group by the new column and use COUNT as the aggregation, but I'd be inclined to that in DAX, as that is analysis. So

Expired Count =
CALCULATE(
    COUNTROWS( MyTable ),
    MyTable[ExpiredField] = "Expired"
)





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you

Greg_Deckler
Community Champion
Community Champion

@Jay2077 You are mixing DAX and M. In M you would use something like DateTime.LocalNow()



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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