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
harshagraj
Post Partisan
Post Partisan

Datediff for alternate rows

Hello All,

 

How do it get date diff in sec. It should be group by ModelNr and Station Nr. 
Eg: Datediff(17-11-2020 14:46:02,17-11-2020 14:46:11,Sec)

 

Snip.png

4 REPLIES 4
harshagraj
Post Partisan
Post Partisan

Hello @Anonymous  thanks a lot helping. But unfortunately i cant do column because its live connection. And i tried the measur but i am getting wrong values. Please see the attached.snip6.JPG

Anonymous
Not applicable

Hi @harshagraj ,

According to the official document, it may caused by some limitations...

I did it in three ways after grouping ModelNr and Station Nr columns, please try

ModelNrStation =
[ModelNr ] & [Station Nr]
Measure = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[DepositCarrier_C] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[ModelNrStation] = MAX ( 'Table'[ModelNrStation] )
                && 'Table'[DepositCarrier_C] < MAX ( 'Table'[DepositCarrier_C] )
        )
    ),
    MAX ( 'Table'[PreStopperArrival_C] ),
    SECOND
)
ColumnMethod1 = 
DATEDIFF (
    [DepositCarrier_C],
    MINX (
        FILTER (
            'Table',
            [ModelNr ] = EARLIER ( [ModelNr ] )
                && [Station Nr] = EARLIER ( [Station Nr] )
                && [PreStopperArrival_C] > EARLIER ( [PreStopperArrival_C] )
        ),
        [PreStopperArrival_C]
    ),
    SECOND
)
ColumnMethod2 = 
DATEDIFF (
    CALCULATE (
        MAX ( 'Table'[DepositCarrier_C] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ModelNrStation] ),
            [DepositCarrier_C] < EARLIER ( 'Table'[DepositCarrier_C] )
        )
    ),
    [PreStopperArrival_C],
    SECOND
)

My final output looks like this:

11.20.2.1.PNG

Here is the pbix file.

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

amitchandak
Super User
Super User

@harshagraj , Try a column like

 

datediff(minx(filter(table, [ModelNr] =earlier([ModelNr]) && [Station Nr] =earlier([Station Nr]) && [prestoparrivalC] > earlier([prestoparrivalC])),[prestoparrivalC]),[prestoparrivalC] , second)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello thankyou so much for the reply. I tried inserting a Measure and I am on Direct Query mode. I am getting below error. I am not getting a column after Earlier. Am i missing something? Please help snip1.JPG

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