Forum Discussion

wouter-GJI's avatar
wouter-GJI
New Member
3 years ago
Solved

Time difference with values in the same column

Dear fellow PowerBi-ers,

 

I started PowerBI about a year ago and have learned a lot from this forum but now I am a bit stuck.

 

I want to calculate how long a product was in a certain status and I found a formula but its needs some tweaking.

 

The current formula  (new column):

Duration (min) =

var Temp =

    TOPN(

        1,

        Filter (

            'ProductLogs',

            'ProductLogs'[ProductID] = EARLIER('ProductLogs'[ProductID])

                && 'ProductLogs'[Timestamp] < EARLIER('ProductLogs'[Timestamp])

        ),

        [Timestamp], DESC

    )

Return

DATEDIFF(MINX(Temp,[Timestamp]),'ProductLogs'[Timestamp],MINUTE)

 

This returns the correct number but puts it in the wrong row.


On top of this, I want to include that whenever the product in its current/last status its calculates the difference with the current time.

 

Hope you can help. Thanks in advance