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
dave_adlard
Frequent Visitor

In DATEDIFF function the start date cannot be greatert than the end date

This is tipping me over the edge. I have an excel spreadsheet that I have imported into Power BI.

 

I have filtered the result so only 3 records appear.

The next review date are the 9th, 12th and 12th again of March 2018 and the exposure start daes are  1st April 2018.

 

My new colum is

Days Betwn = DATEDIFF(

(DATEVALUE(Sheet1[Next Review Date])),
(DATEVALUE(Sheet1[Exposure Start Date]))
,DAY)

and I am hit with the error In DATEDIFF function the start date cannot be greatert than the end date

 

Which is obviously not the case. I have edited the query so the value are dates only or date/time and I still get the same error.

Any help would be appreciated.

Do I need to create it as a measure opposed to a column?

Please help?

1 ACCEPTED SOLUTION

HI @dave_adlard

 

Give this a shot

 

Days Betwn =
VAR MinDate =
    MIN (
        DATEVALUE ( Sheet1[Exposure Start Date] ),
        DATEVALUE ( Sheet1[Next Review Date] )
    )
VAR MaxDate =
    MAX (
        DATEVALUE ( Sheet1[Exposure Start Date] ),
        DATEVALUE ( Sheet1[Next Review Date] )
    )
RETURN
    DATEDIFF ( MinDate, MaxDate, DAY )

View solution in original post

5 REPLIES 5
Zubair_Muhammad
Community Champion
Community Champion

HI @dave_adlard

 

Try swapping the dates

 

Days Betwn =
DATEDIFF (
    ( DATEVALUE ( Sheet1[Exposure Start Date] ) ),
    ( DATEVALUE ( Sheet1[Next Review Date] ) ),
    DAY
)

Thanks for getting back to me unfortunatey I get the same error. Any other ideas

HI @dave_adlard

 

Give this a shot

 

Days Betwn =
VAR MinDate =
    MIN (
        DATEVALUE ( Sheet1[Exposure Start Date] ),
        DATEVALUE ( Sheet1[Next Review Date] )
    )
VAR MaxDate =
    MAX (
        DATEVALUE ( Sheet1[Exposure Start Date] ),
        DATEVALUE ( Sheet1[Next Review Date] )
    )
RETURN
    DATEDIFF ( MinDate, MaxDate, DAY )

that worked, thanks so much. Can you please explain to me?

HI @dave_adlard

 

Actually DateDiff takes the following arguments

 

DATEDIFF(<start_date>, <end_date>, <interval>)  

 

Startdate can't be later than end_date ....otherwise it will throw an error..

 

Thats why we used Min and Max functions to ensure earlier date comes in the first argument and later date comes in the second argument of DATEDIFF

 

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.