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
lcasey
Post Prodigy
Post Prodigy

DATEDIFF, TODAY doesnt work.

Hello,

 

When using This formula: Offline = DATEDIFF(Max('hardware'[Last Count]),Today(),DAY) I get an error

 

The start date cannot be greater than the end date.  I should get a 0 when the two dates are the same.

 

if I use this:  Offline = DATEDIFF(Max('hardware'[Last Count]),Today()+ 1,DAY)

 

It works but is off by 1 day and never shows a zero.

 

NOTE: I have to do conditional formating so I MUST use a mesure as Power BI can not even do conditional formating on columns.

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

TODAY( ) should not be a problem.

Try this Measure which should work!

If it works you have days in the [Last Count] column that are later than today!

 

Offline =
    SWITCH (
        TRUE (),
        TODAY () < MAX ( 'hardware'[Last Count] ), -1 * DATEDIFF ( TODAY (), MAX ( 'hardware'[Last Count] ), DAY ),
        TODAY () > MAX ( 'hardware'[Last Count] ), DATEDIFF ( MAX ( 'hardware'[Last Count] ), TODAY (), DAY ),
        0
    )

DATEDIFF Example2.png

View solution in original post

3 REPLIES 3
Sean
Community Champion
Community Champion

TODAY( ) should not be a problem.

Try this Measure which should work!

If it works you have days in the [Last Count] column that are later than today!

 

Offline =
    SWITCH (
        TRUE (),
        TODAY () < MAX ( 'hardware'[Last Count] ), -1 * DATEDIFF ( TODAY (), MAX ( 'hardware'[Last Count] ), DAY ),
        TODAY () > MAX ( 'hardware'[Last Count] ), DATEDIFF ( MAX ( 'hardware'[Last Count] ), TODAY (), DAY ),
        0
    )

DATEDIFF Example2.png

There are no dates past 11/18/2016 so I am not sure why datediff doesnt work

Yes that works as expected.    Wow, a simple datediff doesnt work.

 

It  seems counter productive to write several lines of code just to get the difference between two dates.

 

Thank you very Much!!!  Hopefully Microsoft will hire better Power BI developers so that Huge lines of code are not eedd for everything.

 

Thanks!

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.