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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

DATEDIFF with filter

Hallo everybody,

 

I have a table that looks something like this,

Jobold statusnew statusold date
115728oTG18-1-2018
115728TGB2-3-2018
115728BA2-3-2018
200BTG6-2-2019
200TGB7-2-2019
200BA8-2-2019

 

I need to now when a job has a new status B (busy) how long did this take?

so for example joborder 115728 got the status B at 2-3-2018, therefore it has status TG 18-1-2018.

the outcome must be the datedifferents between 2-3-2018-18-1-2018 in days.

 

can somebody help me with a measure or a calculated column if a measure is not possible?

 

Kind regards,

Charaf

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

This code does exactly what you need it to do.

 

Previous Date =
VAR PreviousRow =
    TOPN (
        1;
        FILTER (
            Blad1;
            Blad1[old date] < EARLIER ( Blad1[CRH_REQDATE] )
                && Blad1[job] = EARLIER ( Blad1[job] )
        );
        Blad1[old date]; DESC
    )
VAR PreviousValue =
    MINX ( PreviousRow; Blad1[old date] )
RETURN
    DATEDIFF ( PreviousValue; Blad1[old date]; DAY )

 

If this reply solved your issues be sure to mark it as the solution.

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

 

This code does exactly what you need it to do.

 

Previous Date =
VAR PreviousRow =
    TOPN (
        1;
        FILTER (
            Blad1;
            Blad1[old date] < EARLIER ( Blad1[CRH_REQDATE] )
                && Blad1[job] = EARLIER ( Blad1[job] )
        );
        Blad1[old date]; DESC
    )
VAR PreviousValue =
    MINX ( PreviousRow; Blad1[old date] )
RETURN
    DATEDIFF ( PreviousValue; Blad1[old date]; DAY )

 

If this reply solved your issues be sure to mark it as the solution.

 

Anonymous
Not applicable

shout out to @Anonymous  you the man.

thanks alot

 

Greetings,

Charaf

Anonymous
Not applicable

anyone else who can help me?

Anonymous
Not applicable

End_date =
IF (
Test[new status] = "B",
DATEDIFF (
CALCULATE (
MAX ( Test[old date] ),
FILTER ( Test, Test[old date] < EARLIER ( Test[old date] ) )
),
Test[old date],
DAY
)
)

Anonymous
Not applicable

@Anonymous  thank you for your help.

 

im feeling im getting close.

The picture shows the results that i get. the day counts is not the correct outcoming.

I dont understand where this 4 comes from?  the difference between 30 april 2018 - 1 may 2018 = not 4 days.

can you help me with that?

 

i think CHR_OLDVALUE  and CRH_EVENT is missing in the formula.

 bi status datum.JPG

Anonymous
Not applicable

The formulation of the conditions is ambiguous. Please give a full explanation of what you want to calculate for Job 200 as it looks like a job can go through stage B several times.

Best
D.
Anonymous
Not applicable

Job 200 = new status "B" = old status TG

TG had new status date 6-2-2019 -  B had the new status date 7-2-2019.

 

so the new status B from the old status TG is one day old.

 

I hope this is better. @Anonymous 

 

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.