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
cbouichi
Helper IV
Helper IV

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.

 

shout out to @Anonymous  you the man.

thanks alot

 

Greetings,

Charaf

cbouichi
Helper IV
Helper IV

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  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.

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
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.

Top Solution Authors