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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
LuBS
Regular Visitor

Time difference for each Status in Power Bi

I have a date column, status column,  a reportID column, and other columns (not important for the calculation I am having trouble with) like this

reportID |  date  | Status

1             | date1 | Status 1

1             | date2 | Status 2

1             | date3 | Status 3

1             | date4 | Status 4

2             | date1 | Status 1

2             | date2 | Status 2

2             | date3 | Status 3

....

1000       | date 1000| status 1

I would like to get the time lapse in each status. taking tinto account each report ID. I am not sure how to tackle this. At first, I tried to unpivot columns based on the status, but that did not work. There are millions of reports some with 4 statuses others with more or less than.  I am sure there is another way. Please help. Thank you so much in advance!!

2 REPLIES 2
Anonymous
Not applicable

Hi @LuBS ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column = 
VAR _predate =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER (
            'Table',
            'Table'[reportID] = EARLIER ( 'Table'[reportID] )
                && 'Table'[date] < EARLIER ( 'Table'[date] )
                && 'Table'[Status] <> EARLIER ( 'Table'[Status] )
        )
    )
RETURN
    DATEDIFF ( _predate, 'Table'[date], DAY )

vyiruanmsft_0-1695704110608.png

Best Regards

Greg_Deckler
Community Champion
Community Champion

@LuBS See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors