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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Rebekahjhanson
New Member

Datediff Months: start date cannot be greater than the end date

Hi, I've thoroughly reviewed the other posts on this topic and none of them have a solution that works for my situation.  I need to calculate the months difference between two dates, and in some cases, the start date is greater than the end date.  I cannot just subtract the dates because I need the Months, not the Days.  I've tried to modify the following solutions from previous posts but I get the same error each time:

 

1) 

DateDiffMeasure :=
IF (
    [StartDateField] > [EndDateField],
    0 - DATEDIFF ( [EndDateField], [StartDateField], Month ),
    DATEDIFF ( [StartDateField], [EndDateField], Month )
)

2)

Days =
SWITCH (
    TRUE (),
    [StartDateField] > [EndDateField], -1 * DATEDIFF ( [EndDateField], [StartDateField], Month ),
    [EndDateField] > 'Table'[Target], DATEDIFF ( [StartDateField], [EndDateField], Month ),
    0
)

 

I get the same Datediff error (start date cannot be greater than the end date) regardless of what option I try from previous posts on this topic. 

 

1 REPLY 1
v-haibl-msft
Employee
Employee

@Rebekahjhanson

 

I tried your DAX formula in Feb 2017 version of Power BI Desktop and did not get the Datediff error as below. Could you please provide your PBIX file to me so that I can have a check on it?

 

Datediff Months start date cannot be greater than the end date_1.jpg 

 

Best Regards,

Herbert

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.