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
RDA_PowerBI
Frequent Visitor

DAX Calculating Status Duration and Averages

Hi,

 

I am looking for some input on calculating status duration and averages. We have a table that takes a snapshot of each serial no. daily and what status it is in. Currently 50 million + rows. 

 


Serial History.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I need to calculate the time each Serial No. has spent in it's current status. I started with creating the measure below but the end date is not calculating correctly because a serial can be in the same status multiple times throughout it's life. I am not sure how to index the events:

 

StatusDuration =
VAR StartDate = CALCULATE(
FIRSTNONBLANK('Fixed Asset History'[Date of Record], TRUE),
ALLEXCEPT('Fixed Asset History','Fixed Asset History'[Serial No.],'Fixed Asset History'[Status])
)

VAR EndDate = CALCULATE(
LASTNONBLANK('Fixed Asset History'[Date of Record], TRUE),
ALLEXCEPT('Fixed Asset History','Fixed Asset History'[Serial No.],'Fixed Asset History'[Status])
)
RETURN
IF( StartDate = EndDate,
(DATEDIFF(StartDate, TODAY(), DAY)),
DATEDIFF(StartDate, EndDate, DAY)


) + 1

 

Lastly, I'd like the calculate the average time spent in all statuses once I correctly calculate duration. Would it be best to do a measure for each status?

 

Thank you in advance! 

1 ACCEPTED SOLUTION

Hi @RDA_PowerBI

 

It works for me both in Excel and Power BI desktop

 

I am attaching both files.

 

dur1.png

 

 

View solution in original post

5 REPLIES 5
Zubair_Muhammad
Community Champion
Community Champion

@RDA_PowerBI

 

Try this column

 

Column =
VAR PR =
    TOPN (
        1,
        FILTER (
            'Fixed Asset History',
            [Serial No] = EARLIER ( [Serial No] )
                && [Status] = EARLIER ( [Status] )
                && [Date of Record] < EARLIER ( [Date of Record] )
        ),
        [Date of Record], ASC
    )
VAR Pdate =
    MINX ( PR, [Date of Record] )
RETURN
    IF ( ISBLANK ( PDate ), 1, DATEDIFF ( Pdate, [Date of Record], DAY ) + 1 )

Hi Zubair, 


Thank you for your reply. I tried the calculated column but was unsuccesful: 

Calculated Column.jpg

Hi @RDA_PowerBI

 

It works for me both in Excel and Power BI desktop

 

I am attaching both files.

 

dur1.png

 

 

Heres the Excel file. See the Power Pivot Model

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.