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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Dunner2020
Post Prodigy
Post Prodigy

Date difference when condition met

Hi there, 
 
I am calculating the date difference between two columns with a condition that if Date A column has '1/01/1900' then do not take the difference. Here is my code:
 
Diff_in_days  =
Var retail_notify = MAX('Outages'[Date B])
Var interuption_start = MAX('Outages'[Date A])
Var test_con = FORMAT(retail_notify, "dd/mm/yyyy")
RETURN
CALCULATE( DATEDIFF(retail_notify,interuption_start,DAY), FILTER('Outages and Interruptions',test_con <> FORMAT(DATEVALUE("1/01/1900"),"dd/mm/yyyy"))
)
 
However, it does take the date difference when the Date A column has "1/01/1900". I used the format function because Date A and Date B column has a date/time format. Could anyone help me where am I making the mistake?

 

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Please try this expression

Diff_in_days =
VAR retail_notify =
    MAX ( 'Outages'[Date B] )
VAR interuption_start =
    MAX ( 'Outages'[Date A] )
RETURN
    IF (
        YEAR ( retail_notify ) > 1900,
        DATEDIFF ( interuption_start, retail_notify, DAY )
    )

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

Please try this expression

Diff_in_days =
VAR retail_notify =
    MAX ( 'Outages'[Date B] )
VAR interuption_start =
    MAX ( 'Outages'[Date A] )
RETURN
    IF (
        YEAR ( retail_notify ) > 1900,
        DATEDIFF ( interuption_start, retail_notify, DAY )
    )

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@Dunner2020 , Try like

Diff_in_days =
Var retail_notify = MAX('Outages'[Date B])
Var interuption_start = MAX('Outages'[Date A])
RETURN
CALCULATE( DATEDIFF(retail_notify,interuption_start,DAY), FILTER('Outages and Interruptions',not(isblank(retail_notify)) && retail_notify <> DATE(1900,01,01))
)

@amitchandak ,

 

I tried that but no luck. Here is the output

 

myasir_0-1596141134016.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.